我正在做一个代码,发送一封电子邮件给买家的代码,(这也被插入到一个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);
}
2条答案
按热度按时间0g0grzrc1#
@阿诺德这就是它给我的结果
)
yeotifhr2#
如果你想知道文章中的所有变量,你可以显示它们。因为paypal调用了你的链接,所以你会想把它们放进日志文件或者别的什么。
更多信息请参见: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-交易类型
不管怎样,如果我是你,我会在购买前询问客户关于他们电子邮件的情况,并确保其安全,因为他们可能永远不会阅读他们的贝宝电子邮件或有不同的偏好。