doupu7651 2019-03-05 17:56
浏览 11

PHP mysqli_query和邮件功能不起作用[重复]

So I am using PaySera payment system. What I am trying to make is - When PaySera receives payment, all data gets inserted into MySQL database and user gets email.

There is redirect.php [passes data to paysera]

<?php

require_once('WebToPay.php');
require_once ('../config.php');

$name = $_POST['name'];
$email = $_POST['email'];
$phoneNumber = $_POST['telnr'];
$book = $_POST['price'];
$orderis = date("ozhs");

switch($book) {
    case 1: {
        $price = $firstBookPrice;
        $kursai = $firstBookTitle;
        break;
    }
    case 2: {
        $price = $secondBookPrice;
        $kursai = $secondBookTitle;
        break;
    }
    case 3: {
        $price = $thirdBookPrice;
        $kursai = $thirdBookTitle;
        break;
    }
    default: {
        header("Location: ../index.php");
        die();
    }
}

$kaina = preg_replace("/[.€]/", '', $price);

function get_self_url() {
    $s = substr(strtolower($_SERVER['SERVER_PROTOCOL']), 0,
                strpos($_SERVER['SERVER_PROTOCOL'], '/'));

    if (!empty($_SERVER["HTTPS"])) {
        $s .= ($_SERVER["HTTPS"] == "on") ? "s" : "";
    }

    $s .= '://'.$_SERVER['HTTP_HOST'];

    if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80') {
        $s .= ':'.$_SERVER['SERVER_PORT'];
    }

    $s .= dirname($_SERVER['SCRIPT_NAME']);
    return $s;
}

try {
    $self_url = get_self_url();

    $request = WebToPay::redirectToPayment(array(
        'projectid'     => $pid,
        'sign_password' => $pPW,
        'orderid'       => $orderis,
        'p_email'       => $email,
        'p_firstname'   => $name,
        'p_lastname'    => ' ',
        'amount'        => $kaina,
        'telNr'         => $phoneNumber,
        'kursai'        => $kursai,
        'currency'      => 'EUR',
        'country'       => 'LT',
        'accepturl'     => $self_url.'/accept.php',
        'cancelurl'     => $self_url.'/cancel.php',
        'callbackurl'   => $self_url.'/callback.php',
        'test'          => 1,
        'type'          => 'macro',
    ));
}

catch (WebToPayException $e) {
    echo get_class($e) . ': ' . $e->getMessage();
}

and callback.php [receives data when payment is made]

<?php

require_once('WebToPay.php');
include 'mysqli.php';

try {
    $response = WebToPay::checkResponse($_GET, array(
        'projectid'     => $pid,
        'sign_password' => $pPW,
    ));

    if ($response['test'] != '0') throw new Exception('Ijungtas test rezimas');
    if ($response['type'] != 'macro') throw new Exception('Tik makro callback galimas');

    $amount = $response['amount'];
    $name = $response['p_firstname'];
    $telnr = $response['telNr'];
    $kursai = $response['kursai'];
    $email = $response['p_email'];
    $orderid = $response['orderid'];

    $sql = "INSERT INTO `boughtCourses`(`Vardas`, `ElPastas`, `Kursai`, `TelNR`) VALUES ('$name', '$email', '$kursai', '$telnr')";
    mysqli_query($conn, $sql);

    $subject = "Million.lt / Apmokėjimas sėkmingas";
    $txt =
    "
    <html>
    <head>
    </head>
    <body>
        Sveiki ".$name.",<br><br>
        Jūs sėkmingai apmokėjote už kursus. Su jumis greitu metu susisieks mūsų vadybininkas.<br><br>
        <b>Užsakymo detalės:</b><br>
        Kursų pavadinimas: ".$kursai."
        Užsakymo numeris: ".$orderid."
    </body>
    </html>
    ";

    $headers  = 'MIME-Version: 1.0' . "
";
    $headers .= 'Content-type: text/html; charset=utf-8' . "
";
    $headers .= 'From: info@million.lt <info@million.lt>' . "
";

    mail($email, $subject, $txt, $headers);

    echo "OK";
}

catch (Exception $e) {
    echo get_class($e) . ': ' . $e->getMessage();
}

mysqli.php

<?php

    /*$file = basename(__FILE__);
    if(preg_match("/$file/", $_SERVER['REQUEST_URI'])){        
        header("Location: ../index.php");
        die();
    }*/

    include '../config.php';

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("[MySQL] Prisijungimas nepavyko: #" . $conn->connect_error);
    }

?>

paysera receives all data correctly but callback.php doesn't insert any data or sends email

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 制裁名单20240508芯片厂商
    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接