PHP mysqli_query和邮件功能不起作用

时间:2019-03-05 17:56:38

标签: php mysqli

所以我正在使用PaySera付款系统。我想做的是-当PaySera收到付款时,所有数据都会插入MySQL数据库中,并且用户会收到电子邮件。

有redirect.php [将数据传递到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();
}

和callback.php [付款时接收数据]

<?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' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: info@million.lt <info@million.lt>' . "\r\n";

    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正确接收所有数据 但是callback.php不会插入任何数据或发送电子邮件

0 个答案:

没有答案