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