2013-09-25 43 views
0

当我发送IPN时,表示它已成功发送。但是,我从未收到我的测试电子邮件中的电子邮件。我的代码导致它不发送有什么问题?另外,当我准备好向公众开放时,我将如何将邮件从[email protected]更改为购买我的邮件的个人的邮件?我对PHP不太了解,这是我第一次尝试IPN,但我正在帮助他们的网站开展一项非盈利性业务,而且我在解决这个问题上遇到了一些麻烦。任何帮助将不胜感激,提前谢谢。PayPal IPN电子邮件不能正常工作

<?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 = '[email protected]'; 
$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); 
} 
?> 

回答

0

您需要更新从HTTP脚本/ 1.0为HTTP/1.1 并添加两个主机:和连接:条目。

$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"; 

应该

$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";