turnej Posted January 13, 2011 Share Posted January 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/ Share on other sites More sharing options...
raknjak Posted January 13, 2011 Share Posted January 13, 2011 probably using Yahoo or Gmail? Always use a catch-all email address on your own domain. e.g.: catchall@mydomain.com Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158906 Share on other sites More sharing options...
turnej Posted January 13, 2011 Author Share Posted January 13, 2011 I was using an admin on my own doman e.g admin@mydomain.com Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158908 Share on other sites More sharing options...
denno020 Posted January 13, 2011 Share Posted January 13, 2011 How do you know that your IPN script is already actually working? I have just been tinkering with IPN myself, and was thinking of adding exactly what you've done, however I didn't anticipate any problems. You are setting up your test data in the IPN simulator to send a payment of exactly 29.99 and that the currency is in GBP? So basically, are you absolutely sure that your script is working, and that you are getting into the if statements correctly? Denno Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158925 Share on other sites More sharing options...
turnej Posted January 13, 2011 Author Share Posted January 13, 2011 I downloaded most of the IPN code from Paypal so I am pretty sure it is working correctly Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158946 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2011 Share Posted January 13, 2011 Any script involving payments should record (log to a file or log to a database table) the actual information that it received. This will provide you with a record on your server of both successful and failed payments and having that information will let you troubleshoot what your code is doing (at this point, you don't even know if the mail() function was called.) You need to find out what execution path the following logic tests are taking - if (strcmp ($res, "VERIFIED") == 0) { if ($payment_status=="Completed") { if ($payment_amount==29.99&&$payment_currency=="GBP") { What exactly is in $res, $payment_status, $payment_amount, and $payment_currency? Edit: you also need to record when you get a // HTTP ERROR from the fsockopen() statement. Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158954 Share on other sites More sharing options...
denno020 Posted January 14, 2011 Share Posted January 14, 2011 I too grabbed my IPN script from PayPal Developers site, however I still had to test it extensively, as it didn't work right away. There is a few settings that need to be changed in the seller settings of the PayPal account. It's not simply a matter of uploading the script to your site and then it all works. I suggest you look for some YouTube videos on how to set up PayPal IPN. If you can't find anything after giving it an honest look, I'll help you with what settings need to be changed. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1159248 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.