[英]PayPal IPN email not working
When I send the IPN, it says it was sent successfully. 当我发送IPN时,它说发送成功。 However, I never receive an email at my test email.
但是,我从未在测试电子邮件中收到任何电子邮件。 What is wrong with my code to cause it to not send?
我的代码有什么问题导致它无法发送? Also, when I am ready for it to be open to the public, how would I change the ToEmail from xxx@myemail.com to the email of the individual that purchased my item?
另外,当我准备好向公众开放时,如何将ToEmail从xxx@myemail.com更改为购买了我的商品的个人的电子邮件? I'm not very knowledgeable with PHP, this is my first time attempting an IPN but I'm helping a nonprofit business with their website and I'm having a bit of trouble getting this to work.
我对PHP不太了解,这是我第一次尝试IPN,但我正在帮助其网站从事非营利性业务,但让它无法正常工作有点麻烦。 Any help would be greatly appreciated, thank you in advance.
任何帮助将不胜感激,在此先感谢您。
<?php
//Build the data to post back to Paypal
$postback = 'cmd=_notify-validate';
// go through each of the posted vars and add them to the postback variable
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$postback .= "&$key=$value";
}
// build the header string to post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($postback) . "\r\n\r\n";
// Send to paypal or the sandbox depending on whether you're live or developing
//comment out one of the following lines
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);//open the connection
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// or use port 443 for an SSL connection
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp)
{
// HTTP ERROR Failed to connect
//error handling
}
else // if we've connected OK
{
fputs ($fp, $header . $postback);//post the data back
while (!feof($fp))
{
$response = fgets ($fp, 1024);
if (strcmp ($response, "VERIFIED") == 0) //It's verified
{
$ToEmail = 'xxx@myemail.com';
$EmailSubject = 'Subject Here';
$mailheader = "From: ".$_POST['receiver_email']."\r\n";
$mailheader .= "Reply-To: ".$_POST['receiver_email']."\r\n";
$MESSAGE_BODY = "Name: ".$_POST['first_name']."";
$MESSAGE_BODY .= "
I will write my message here.";
$MESSAGE_BODY .= "
Thank you,
MY COMPANY NAME";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader);
}
else if (strcmp ($response, "INVALID") == 0)
{
//the Paypal response is INVALID, not VERIFIED
// This implies something is wrong
}
} //end of while
fclose ($fp);
}
?>
You need to update the script from HTTP/1.0 to HTTP/1.1 and add both Host: and Connection: entries. 您需要将脚本从HTTP / 1.0更新到HTTP / 1.1,并添加Host:和Connection:条目。
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($postback) . "\r\n\r\n";
Should be 应该
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($postback) . "\r\n\r\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.