dsa99349 2011-06-14 16:39
浏览 25

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

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

";

// 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 
 $street 
 $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";
                            $mail_Body = "Hello $payer_ name , thank you for purchasing the $item_name from $buisness , your order ID is as follows: $txn_id; . 
 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 . "

" . $mail_Body, $mail_From);

                        }
  • 写回答

2条回答 默认 最新

  • dongrunying7537 2011-06-14 17:45
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制