0

I have set sandbox PayPal account. When transaction is made the IPN url is called, but nothing happens. The mail should be sent via php mail function. I checked IPN history and it shows that call was made to the script, but mail is not sent. Here is the script:

<?php

$con=mysqli_connect("something", "something", "something") or die(mysql_error());
mysqli_select_db($con,"some_db") or die(mysql_error());

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// 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($req) . "\r\n\r\n";

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$to = "someone@hotmail.com";
$subject = 'something';
$headers = 'From:noreply@something.com' . "\r\n";
$message = '

bla bla bla

';
mail($to, $subject, $message, $headers);



// PAYMENT VALIDATED & VERIFIED!

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

}
}
fclose ($fp);
}
?>

Regards

Ricky97
  • 79
  • 8
  • Have you debugged the script? You should have it log what it received to a file, as well as whether it was able to successfully validate the IPN as VERIFIED or not, and also have checked your server-side logs for any errors that may have occurred in the process. – Preston PHX Jun 06 '20 at 09:54
  • You have an error. [`mysql_error()`](https://www.php.net/manual/en/function.mysql-error.php) worked only for the old API. Please consider switching error mode on instead. [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman Jun 06 '20 at 22:32

0 Answers0