Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/224313-php-mail-help/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158925
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1158954
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/224313-php-mail-help/#findComment-1159248
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.