paypal ipn不发送payer\电子邮件变量

s8vozzvw  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(336)

我正在做一个代码,发送一封电子邮件给买家的代码,(这也被插入到一个mysql数据库),她或他可以赎回代码激活他的帐户上的软件,听起来不错,但问题是,付款人的电子邮件viriable不起作用。其余的变量如item numbers和al可以工作,但是payer变量不能工作。这是我的密码:

<?php
require_once 'PHPMailer/PHPMailer.php';
require_once 'PHPMailer/SMTP.php';
require_once 'PHPMailer/Exception.php';
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
header('Location: index.php');
exit();
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi- 
bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . 
http_build_query($_POST));
$response = curl_exec($ch);
curl_close($ch);

if ($response == "VERIFIED" && $_POST['receiver_email'] == 
"-") 
{
    $vijftien = $_POST['payer_email'];
    $name = $_POST['first_name'] . " " . $_POST['last_name'];

    $price = $_POST['mc_gross'];
    $currency = $_POST['mc_currency'];
    $item = $_POST['item_number'];
    $paymentStatus = $_POST['payment_status'];

     function generateRandomString($length = 10)
     {
         $characters = 
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
          $randomString = '';
          for ($i = 0; $i < $length; $i++) {
              $randomString .= $characters[rand(0, $charactersLength - 
1)];
          }
          return $randomString;

      }
  if ($item == "leerlingentool") {

    $kaas = generateRandomString();
    $body1 = "Hoi,
     bedankt voor het kopen van onze sofftware!
      Hier heb je een token. Die kun je verzilveren op 
leerlingentool.website/token.php om de software op jou account te activeren
      MVG Wouter Boogaard" . $kaas;
         $tabel = "leerlingentool";
        //if ($item == "leerlingentool" && $currency == "EUR" && 
$paymentStatus == "Completed" && $price == 2,99) {

    }
     if($item == "crashtool"){
         $kaas = generateRandomString();
         $body1 = "Hoi,
          bedankt voor het kopen van onze sofftware!
          Hier heb je een token. Die kun je verzilveren op 
leerlingentool.website/token1.php om de software op jou account te 
 activeren
           MVG Wouter Boogaard" . $kaas;
        $tabel = "crashtool";
    }

    $mail = new PHPMailer();
    $mail ->IsSmtp();
    $mail ->SMTPAuth = true;
    $mail ->SMTPDebug = 1;
    $mail ->SMTPSecure = 'ssl';
    $mail ->Host = 'smtp.gmail.com';
    $mail ->Port = 465; //or 587 use tls if so
    $mail ->IsHTML();
    $mail ->Username = "-";
    $mail ->Password = "-";
    $mail ->Subject = "Je aankoop bij EvolvingDesk Software";
    $mail ->Body = "$body1";
    $mail ->AddAdress($vijftien);
    $mail ->setFrom('-', 'EvolvingDesk Software');
    $mail ->Send();
    $db = mysqli_connect("-", "-", "-", 
    "-");
    $sql = "INSERT INTO $tabel (token) VALUES ('$kaas')";

    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
    $koektrommel = $mail->ErrorInfo;
    fwrite($myfile, $vijftien);
    fclose($myfile);

    mysqli_query($db, $sql);
    mysqli_close($db);

}

更新代码:

use PHPMailer\PHPMailer\PHPMailer;
require "PHPMailer/PHPMailer.php";
require "PHPMailer/Exception.php";
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
header('Location: index.php');
exit();
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi- 
bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . 
http_build_query($_POST));
$response = curl_exec($ch);
curl_close($ch);

if ($response == "VERIFIED" && $_POST['receiver_email'] ==
"-")
{
 $vijftien = $_POST['payer_email'];
 $name = $_POST['first_name'] . " " . $_POST['last_name'];

 $price = $_POST['mc_gross'];
 $currency = $_POST['mc_currency'];
 $item = $_POST['item_number'];
 $paymentStatus = $_POST['payment_status'];

  function generateRandomString($length = 10)
  {
    $characters =
        '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength -
            1)];
    }
    return $randomString;

}
if ($item == "leerlingentool" && $paymentStatus == "Completed")  {

    $kaas = generateRandomString();
    $body1 = "Hoi,
 bedankt voor het kopen van onze sofftware!
  Hier heb je een token. Die kun je verzilveren op 
leerlingentool.website/token.php om de software op jou account te activeren
  MVG Wouter Boogaard" . $kaas;
    $tabel = "leerlingentool";
    //if ($item == "leerlingentool" && $currency == "EUR" &&

    }
 if($item == "crashtool" && $paymentStatus == "Completed"){
     $kaas = generateRandomString();
     $body1 = "Hoi,
      bedankt voor het kopen van onze sofftware!
      Hier heb je een token. Die kun je verzilveren op 
leerlingentool.website/token1.php om de software op jou account te 
 activeren
       MVG Wouter Boogaard" . $kaas;
     $tabel = "crashtool";
 }

$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPAuth = true;
$mail ->SMTPDebug = 1;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = 'smtp.gmail.com';
$mail ->Port = 465; //or 587 use tls if so
$mail ->IsHTML();
$mail ->Username = "-";
$mail ->Password = "-";
$mail ->Subject = "Je aankoop bij EvolvingDesk Software";
$mail ->Body = "$body1";
$mail ->AddAdress($_POST['payer_email']);
$mail ->setFrom('-', 'EvolvingDesk Software');
$mail ->Send();
$db = mysqli_connect("", "", "", 
"");
$sql = "INSERT INTO $tabel (token) VALUES ('$kaas')";

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$koektrommel = $mail->ErrorInfo;
fwrite($myfile, $_POST['payer_email']);
fclose($myfile);

mysqli_query($db, $sql);
mysqli_close($db);

}
0g0grzrc

0g0grzrc1#

@阿诺德这就是它给我的结果

Array
(
 [payment_type] => instant
 [payment_date] => 13:23:01 Nov 29, 2018 PST
 [payment_status] => Completed
 [address_status] => confirmed
 [payer_status] => verified
 [first_name] => wouter
 [last_name] => Smith
 [payer_email] => boogwout@gmail.com
 [payer_id] => TESTBUYERID01
 [address_name] => -
 [address_country] => United States
 [address_country_code] => US
 [address_zip] => 95131
 [address_state] => CA
 [address_city] => San Jose
 [address_street] => 123 any street
 [business] => 116106@guido.nl
 [receiver_email] => 116106@guido.nl
 [receiver_id] => 116106@guido.nl
 [residence_country] => US
 [item_name] => something
 [item_number] => leerlingentool
 [quantity] => 1
 [shipping] => 3.04
 [tax] => 2.02
 [mc_currency] => USD
 [mc_fee] => 0.44
 [mc_gross] => 12.34
 [mc_gross_1] => 9.34
 [txn_type] => web_accept
 [txn_id] => 826676261
 [notify_version] => 2.1
 [custom] => xyz123
 [invoice] => abc1234
 [test_ipn] => 1
 [verify_sign] => kroost-bettonviel.shinydief(this is not a real sign, lol)

)

yeotifhr

yeotifhr2#

如果你想知道文章中的所有变量,你可以显示它们。因为paypal调用了你的链接,所以你会想把它们放进日志文件或者别的什么。

file_put_contents('log', print_r($_POST, true));

更多信息请参见:http://php.net/manual/en/function.file-put-contents.php 如果它被加进去,其他的东西就坏了。。。而且它应该根据paypal添加:
https://developer.paypal.com/docs/classic/ipn/integration-guide/ipnintro/#ipn-协议和体系结构
同时检查:https://developer.paypal.com/docs/classic/ipn/integration-guide/ipnandpdtvariables/#ipn-交易类型
不管怎样,如果我是你,我会在购买前询问客户关于他们电子邮件的情况,并确保其安全,因为他们可能永远不会阅读他们的贝宝电子邮件或有不同的偏好。

相关问题