Hi Guys,
I am using IPN with my site and want to send an email to the purchasers once the purchase is complete, but during testing in sandbox the email is not being sent and I can's see why, any ideas?
<?php
// PHP 4.1
// 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.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status=="Completed")
{
if ($payment_amount==29.99&&$payment_currency=="GBP")
{
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
any help much appreciated.
PHP Help
Moderator: General Moderators
Re: PHP Help
Are you sure you're getting a successful payment response message? Also, please put PHP code tags around your PHP code.
Code: Select all
echo $payment_status;
if ($payment_status=="Completed")
{
echo "<br/>$payment_amount $payment_currency";
if ($payment_amount==29.99&&$payment_currency=="GBP")
{
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
}
}
Re: PHP Help
Not sure if this helps or not but I had a problem with email not sending and found that this part of your code...
Should look like this...
That's what fixed my problem, worth a shot.
Code: Select all
// 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.sandbox.paypal.com', 443, $errno, $errstr, 30);
Code: Select all
// 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.sandbox.paypal.com', 443, $errno, $errstr, 30);
Re: PHP Help
The problem could be email not sent or something else in your PayPal communication.
Just test it separately - make a file with only the mail() function & run it with your email address.
Did you get an email?
If yes, the problem is with your paypal communication.
If no, then sendmail isnt configured correctly on the server.
Here is a mail function that should work for you to test.
the -f attribute can sometimes help for servers that strip headers, so use that to be safe.
Just test it separately - make a file with only the mail() function & run it with your email address.
Did you get an email?
If yes, the problem is with your paypal communication.
If no, then sendmail isnt configured correctly on the server.
Here is a mail function that should work for you to test.
the -f attribute can sometimes help for servers that strip headers, so use that to be safe.
Code: Select all
$to="myname@server.com";
$subject = "This is a test";
$header = "From: website@server.com\n";
$message = "============\n";
$message .="This is a test.\n";
$message .="============\n";
mail($to,$subject,$message,$header, '-f website@server.com');