YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

PayPal send automated customized receipt for donations Options
studiobe
#1 Posted : Monday, November 23, 2009 8:28:49 AM
Rank: Starting Member

Groups: Registered

Joined: 11/23/2009
Posts: 1
Location: Midwest
I keep trying to figure this out, but it doesn't seem to be working for me. I am pretty illiterate when it comes to developing. I am trying to get an automated receipt sent out to donors when the click on the donate button and pay through paypal. I would also like a carbon copy of this customized receipt to be sent to the owner of the site. I want this to be in the form of a letter that is customized with their payment amount and name to be sent after they have went through paypal. Any help appreciated! Thanks!
Sponsor  
 
nds_webdesign
#2 Posted : Wednesday, November 25, 2009 3:35:19 AM
Rank: Junior Member

Groups: Registered

Joined: 10/15/2009
Posts: 159
Location: Omaha, NE USA
Here is a very basic sample script that would send an email to a buyer via IPN.

This is in PHP, you could change the line:

Code:
$email_msg = "Thanks for your purchase";


to reflect the actual message. in this case the buyer would receive an email where the body of the email would say "Thanks for your purchase".

Code:

<?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'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

//set email variables
$From_email = "From: mybiz@domain.com";
$Subject_line = "Thank You for your purchase";

$email_msg = "Thanks for your purchase";
$email_msg .= "\n\nThe details of your order are as follows:";
$email_msg .= "\n\n" . "Transaction ID: " .  $txn_id ;
$email_msg .= "\n" . "Payment Date: " . $payment_date;

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_email;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);


}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = $From_email;
$mail_To = $receiver_email;
$mail_Subject = "INVALID IPN POST";
$mail_Body = "INVALID IPN POST. The raw POST string is below.\n\n" . $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>



If you have further questions or would like to get a quote for a custom script that does this please let me know.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFVision Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.152 seconds.