I have a small action script that I run when someone buys something with Paypal.
Using the notify_url=http://www.mysite.com/my-automatic-script.php
I am using the mail() feature on my site to automatically grabs email address and update the user with some info.
Everything runs perfect, but the script just keeps on repeating and repeating itself. (i am getting emailed every 5 mins with this) ..
script here:
require('wp-blog-header.php');
$user_email = trim(isset($_POST['payer_email']) ? $_POST['payer_email'] : "");
$us_firstname = trim(isset($_POST['first_name']) ? $_POST['first_name'] : "");
$us_lastname = trim(isset($_POST['last_name']) ? $_POST['last_name'] : "");
$randomkey = rand(0, 9999);
$user_name = $us_lastname . '_' . $randomkey;
$user_id = email_exists( $user_email );
if ( !$user_id ) {
$random_password = wp_generate_password ( 12, false, false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
wp_update_user( array ('ID' => $user_id, 'first_name' => $us_firstname, 'last_name' => $us_lastname) ) ;
update_user_meta( $user_id, 'subscription_status', 'subscribed' );
update_user_meta( $user_id, 'subscription_level', '3' );
update_user_meta( $user_id, 'subscription_pack', 'Manual' );
update_user_meta( $user_id, 'subscription_key', '' );
update_user_meta( $user_id, 'subscription_expires', date('Ymd', strtotime('+ 365 day')) );
// The message
$headers = "From: no-reply@mysite.com";
$message2 = "Here is my message";
// Send
mail($user_email, 'Welcome to my site', $message2, $headers);
//end mail
break;
} else {
$headers = "From: no-reply@mysite.com";
$message2 = "This user is already registered";
mail('me@me.com', 'Purchase from Registered User', $message2, $headers);
}
break;
Thanks in advance! Is break; sufficient for this?
Another UPDATE:
I went the PDT PayPal route:
IT seems like this is working!
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "my-secret-code";
$req .= "&tx=$tx_token&at=$auth_token";
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0rn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($req) . "rnrn";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "rn") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
// parse the data
$lines = explode("n", $res);
$keyarray = array();