开发者

send email after transaction with paypal IPN

I have got some sample code from PayPalTech.com and have edited to fit my needs. Basically all I want to have work is for an email to be sent to the customer after the order is completed. I have edited the php code to fit my needs but for some reason it isn't working anymore now. The original code was meant to just echo all the php variables from the IPN and end it in an email to myself. Here is the code that I have so far.

<?php

// 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";

// If testing on Sandbox use: 
// $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: www.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.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'];


//transaction ID
$txn_id = $_POST['txn_id'];


//ATEKDesign
$business = $_POST['business'];

//payer email
$payer_email = $_POST['payer_email'];

//create payer name
$payer_firstname = $_POST['first_name'];
$payer_lastname = $_POST['last_name'];
$payer_name = $payer_firstname . " " . $payer_lastname;

//create payer address
$name = $_POST['address_name'];
$street = $_POST['address_street'];
$city = $_POST['address_city'];
$state = $_POST['address_state'];
$zip = $_POST['address_zip'];

$address = "$name \n $street \n $city $state $zip";









if (!$fp) 
{
    // HTTP ERROR
} 

else 
{
    fputs ($fp, $header . $req);
        while (!feof($fp)) 
            {
                $res = fgets ($fp, 1024);
                    if (strcmp ($res, "VERIFIED") == 0) 
                        {
                            // check the payment_status is Completed
                            // check that txn_id has not been previously processed
                            // check that receiver_email is your Primary PayPal email
                            // check that payment_amount/payment_currency are correct
                            // process payment

                            $mail_From = "From: me@mybiz.com";
                            $mail_To = "atekdesigns@gmail.com";
                            $mail_Subject = "VERIFIED IPN";
 开发者_StackOverflow社区                           $mail_Body = "Hello $payer_ name , thank you for purchasing the $item_name from $buisness , your order ID is as follows: $txn_id; . \n We will be using $payer_email to contact you and will be sending you item to $address";
                            $emailtext = blank;



                            mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);

                        }


1) Make sure that you have enabled IPN in your paypal account.
     If not enable the IPN by addibg the ipn page url to paypal.

2) Make sure that paypal is posting values to your ipn page, for that put the following code in your ipn file and complete a payment.

<?PHP
$mail_From = "From: me@mybiz.com";
$mail_To = "atekdesigns@gmail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = "Post: ".serialize($_POST)."<br>";
$emailtext = "blank";

mail($mail_To, $mail_Subject, $emailtext . "\n\n" . $mail_Body, $mail_From);
?>

if you'r receiving the email then check the variables and its values.


What error are you getting? What happens if you remove the mail portion and return to just echoing?

I suggest stepping back - comment out all of your changes as much as possible and still have some rudimentary that works. Then, start uncommenting your code - one snippet at a time - until it doesn't work.

If you provide more detail I may be able to help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜