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

Write email to text file? Options
pxlcreations
#1 Posted : Saturday, February 27, 2010 11:03:03 PM
Rank: Starting Member

Groups: Registered

Joined: 2/27/2010
Posts: 1
Hello all! I've had this paypal IPN for some time now and it works perfectly. So here's what happens (although you all probably know this )

The user pressed "purchase now" on my site and they pay the selected amount, then this script is run somewhere down the line and the paypal users receives an email with the contents below. This works perfectly, but I would like one more thing to happen.

I have an online mailing list that users can subscribe to by clicking a link on my home site. It stores the email address in a text file, which looks like this:


"email@mail.com","1266585584","2323123222"
"email2@mail.com","1266585584","2323123222"
"email3@mail.com","1266585584","2323123222"


I don't know what it would be or where to put it, but it would somehow write the user's paypal email into that text file, so they are subscribed to the mailing list. Here's my IPN 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";
$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";

$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: email@email.com";
$Subject_line = "Thing";
$email_msg = "Body Contents
";

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 = "Oops!";
$mail_Text = "Something went wrong.
";

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

}
}
fclose ($fp);
}
?>



Thank you in advance!
Sponsor  
 
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.170 seconds.