Yes, I have the IPN blues. For the life of me, I can't get my IPN script to either a) function or b) have it read. I setup IPN notification in my paypal account after realizing that it wasn't preset to 'on'. So I entered in my IPN default page in their preference settings which is why you don't see the hidden field 'notify_url' below, or should I add this as a hidden field regardless? I scrapped all the code in the payipn.php script and just had my mail script and I didn't receive anything so that makes me think that PAYPAL isn't even retrieving the page, nor is there any result in the ipn.log that the ipn script creates towards the header code.
//parsed php form
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sales@mydomain.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Mydomain.com">
<input type="hidden" name="item_number" value="bfa7917b54aefbfa2cf5cded9315b7a7">
<input type="hidden" name="notify_url" value="http://www.mydomain.com/cart/payipn.php">
<input type="hidden" name="return" value="http://www.mydomain.com/cart/thanks.php">
<input type="hidden" name="cancel_return" value="http://www.mydomain.com/cart/canceled.php">
<input type="hidden" name="amount" id="amount">
<input type="image" src="images/checkout.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
//payipn.php script
<?php
//------------------------------------------------------------------
// Open log file (in append mode) and write the current time into it.
// Open the DB Connection. Open the actual database.
//-------------------------------------------------------------------
$log = fopen("ipn.log", "a");
fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n");
$db = mysql_connect("#", "#", "#");
mysql_select_db("#",$db);
//------------------------------------------------
// Read post from PayPal system and create reply
// starting with: 'cmd=_notify-validate'...
// then repeating all values sent - VALIDATION.
//------------------------------------------------
$postvars = array();
while (list ($key, $value) = each ($HTTP_POST_VARS)) {
$postvars[] = $key;
}
$req = 'cmd=_notify-validate';
for ($var = 0; $var < count ($postvars); $var++) {
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode ($postvar_value);
}
//--------------------------------------------
// Create message to post back to PayPal...
// Open a socket to the PayPal server...
//--------------------------------------------
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen ($req) . "\r\n\r\n";
$fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);
fwrite($log, "Vals: ". $invoice." ". $receiver_email." ". $item_name." ". $item_number." ". $quantity." ". $payment_status." ". $pending_reason." ".$payment_date." ". $payment_gross." ". $payment_fee." ". $txn_id." ". $txn_type." ". $first_name." ". $last_name." ". $address_street." ". $address_city." ". $address_state . " ".$address_zip." ". $address_country." ". $address_status." ". $payer_email. " ". $payer_status." ". $payment_type." ". $notify_version." ". $verify_sign. "\ n");
//----------------------------------------------------------------------
// Check HTTP connection made to PayPal OK, If not, print an error msg
//----------------------------------------------------------------------
if (!$fp) {
echo "$errstr ($errno)";
fwrite($log, "Failed to open HTTP connection!");
$res = "FAILED";
}
//--------------------------------------------------------
// If connected OK, write the posted values back, then...
//--------------------------------------------------------
else {
fputs ($fp, $header . $req);
//-------------------------------------------
// ...read the results of the verification...
// If VERIFIED = continue to process the TX...
//-------------------------------------------
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
//----------------------------------------------------------------------
// If the payment_status=Completed... Get the password for the product
// from the DB and email it to the customer.
//----------------------------------------------------------------------
if (strcmp ($payment_status, "Completed") == 0) {
$qry = "UPDATE catalog SET pass=\"1\" WHERE session = \"$item_number\"";
$result = mysql_query($qry,$db);
//send email with session variable
$header = "From: sales@mysite.com\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\n";
$header .= "X-Mailer: PHP / ".phpversion()."\n";
$message = "<html>\n";
$message .= "<body>\n";
$message .= "<table border=0 cellspacing=0 cellpadding=0>\n";
$message .= "<tr>\n";
$message .= "<td><img src=\"http://www.mysite.com/images/logo.gif\"><br><br>Dear ".$first_name."<br><br><b><font color=red>Your template(s) are
available for download!</font></b><br><br>Thank you for choosing <a href=\"http://www.mysite.com\" target=\"_blank\">mysite.com</a>
for your template needs!.<br><br>Click on the link below to download your template(s). You will be able to access your template downloads for 24 hours after
initial purchase.<br><br><a
href=\"http://www.mysite.com/cart/mytemplates.php?tpl=".$item_number."&fname=".$first_name."\">http://www.mysite.com/cart/mytemplates.php?tpl=".$item_number."&fname=".$first_name."</a><br><br>Sincerely Yours,<br><br>mysite.com Staff";
$message .= "</tr>\n";
$message .= "</table>\n";
$message .= "</body>\n";
$message .= "</html>\n";
$sendto = "".$payer_email.", info@mysite.com";
$subject = "Your Template(s) are available! - mysite.com";
mail($sendto,$subject,$message,$header);
}
//----------------------------------------------------------------------
// If the payment_status is NOT Completed... You'll have to send the
// password later, by hand, when the funds clear...
//----------------------------------------------------------------------
else {
$message .= "Dear Customer,\n Thankyou for your order.\n\nThe link for the item(s) you ordered will be sent to you when the funds have cleared.\n\nThankyou
\n\nsales\@yourdomain.com";
mail($payer_email, "mysite.com - Your Template(s) link...", $message, "From: info@mysite.com\nReply-To:
info@mysite.com");
mail($receiver_email, "mysite.com - Incomplete PayPal TX...", "An incomplete transaction requires your attention.");
} else {
mail($payer_email, "mysite.com - An Error Occurred...", "Dear Customer,\n an error occurred while PayPal was processing your order. It will be investigated by a human at the earliest opportunity.\n\nWe apologise for any inconvenience.", "From: info@mysite.com\nReply-To: info@mysite.com");
mail($receiver_email, "mysite.com - Invalid PayPal TX...", "An invalid transaction requires your attention.");
}
}
}
//--------------------------------------
// Insert Transaction details into DB.
//--------------------------------------
$qry = "INSERT into sales (
invoice, receiver_email, item_name, item_number, quantity, payment_status, pending_reason, payment_date, payment_gross, payment_fee, txn_id, txn_type,
first_name, last_name, address_street, address_city, address_state, address_zip, address_country, address_status, payer_email, payer_status, payment_type,
notify_version , verify_sign )
VALUES
( \"$invoice\", \"$receiver_email\", \"$item_name\", \"$item_number\", \"$quantity\", \"$payment_status\", \"$pending_reason\", \"$payment_date\",
\"$payment_gross\", \"$payment_fee\", \"$txn_id\", \"$txn_type\", \"$first_name\", \"$last_name\", \"$address_street\", \"$address_city\",
\"$address_state\", \"$address_zip \", \"$address_country\", \"$address_status\", \"$payer_email\", \"$payer_status \", \"$payment_type\",
\"$notify_version\", \"$verify_sign\" ) ";
$result = mysql_query($qry,$db);
//-------------------------------------------
// Close PayPal Connection, Log File and DB.
//-------------------------------------------
fclose ($fp);
fclose ($log);
mysql_close($db);
?>