gpt4 book ai didi

php - 使用 Paypal IPN 交易后发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:12 26 4
gpt4 key购买 nike

我从 PayPalTech.com 获得了一些示例代码,并根据我的需要进行了编辑。基本上我想要的工作就是在订单完成后向客户发送一封电子邮件。我已经编辑了 php 代码以满足我的需要,但由于某种原因它现在不再工作了。原始代码只是为了回显来自 IPN 的所有 php 变量,并在给我自己的电子邮件中结束。这是我到目前为止的代码。

<?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";
$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) 确保您的paypal账户已启用IPN。
如果不通过将 ipn 页面 url 添加到 paypal 来启用 IPN。

2) 确保 paypal 正在将值发布到您的 ipn 页面,为此将以下代码放入您的 ipn 文件并完成付款。

<?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);
?>

如果您收到电子邮件,请检查变量及其值。

关于php - 使用 Paypal IPN 交易后发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6346962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com