princeofpersia Posted March 5, 2012 Share Posted March 5, 2012 Hi guys I have IPN setup for my online shop which is working fine but when payment is confirmed, my shop should send a link confirming purchase along with list of items, so I have added that to my IPN, there is an issue, it owuldnt send the email, I have checked every table/column name and they are correct, IPN works because I receive paypal confirmation email and updates database, so something should be wrong with they way I have written the code to send this email. Please find the code below, I have deleted some un-necessary info: <? include ('includes/db.php'); // PHP 4.1 // 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 .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.sandbox.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']; $order_id = mysql_real_escape_string((int)$_POST['custom']); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if ($payment_status=='Completed') { $txn_check=mysql_query("SELECT txn_id FROM orders WHERE txn_id='$txn_id'"); if (mysql_num_rows($txn_check)!=1) { if($receiver_email=='[email protected]'){ ////////// $get=mysql_query("SELECT amount FROM orders WHERE amount='$payment_amount'"); while ($get_row=mysql_fetch_array($get)) { $amount=$get_row['amount']; } if($amount==$payment_amount && $payment_currency=='GBP') { $update=mysql_query("UPDATE orders SET confirmed='1', txn_id='$txn_id' WHERE order_ref='$order_id'"); $select=mysql_query("SELECT * FROM ordered_product WHERE order_ref='$order_id'"); while($row=mysql_fetch_array($select)) { $product_number=$row['product_ref']; $quantity_ordered=$row['quantity_ordered']; $update=mysql_query("UPDATE products SET instock=instock-1 WHERE product_ref='$product_number'"); } $select=mysql_query("SELECT * FROM orders WHERE order_ref='order_id' AND confirmed='1'"); while ($row=mysql_fetch_array($select)) { $order_number=$row['order_ref']; $name=$row['user_name']; $email=$row['user_email']; $address1=$row['address_1']; $address2=$row['address_2']; $address3=$row['address_3']; $city=$row['city']; $postcode=$row['postcode']; $country=$row['country']; $amount=$row['txn_id']; $date=$row['order_date']; } $select=mysql_query("SELECT * FROM ordered_product WHERE order_ref='$order_id'"); while($get_row=mysql_fetch_array($select)) { $product_ref=$get_row['product_ref']; $quantity=$get_row['quantity_ordered']; } $select=mysql_query("SELECT * FROM products WHERE product_ref='$product_ref'"); while($get_row=mysql_fetch_array($select)) { $product_name=$get_row['product_name']; $product_price=$get_row['price']; echo "<table width='439' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='219'>$product_name</td> <td width='120'>$quantity</td> <td width='98'>£$product_price</td> </tr> </table>"; } ///////// $headers=array( 'From:[email protected]', 'Content-Type:text/html' ); $body="<table width='492' border='0' cellspacing='0' cellpadding='0' style='font-family:Verdana, Geneva, sans-serif; font-size:12px; color:#333;'> <tr> <td width='492' height='374' valign='top'><table width='497' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='497' height='97'><img src='../images/logo.png'/></td> </tr> <tr> <td>Thank you for ordering. Your order should arrive in the next 2-3 days.</td> </tr> <tr> <td height='48'><strong>ORDER NUMBER:</strong> $order_number</td> </tr> <tr> <td height='48'><p><strong>DELIVERY ADDRESS: </strong></p> <p>$address1 <br/> $address2 <br/> $address3 <br/> $city <br/> $postcode <br/> $country</p> <p> </p></td> </tr> <tr> <td height='48'><p><strong>YOUR ORDER:</strong></p> <table width='439' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='219'><strong>Item</strong></td> <td width='120'><strong>Quantity</strong></td> <td width='98'><strong>Price</strong></td> </tr> </table><br/> <table width='439' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='219'>$product_name</td> <td width='120'>$quantity</td> <td width='98'>£$product_price</td> </tr> </table> <p> </p></td> </tr> <tr> <td height='48'><p><strong>Sub Total:</strong> £amount<br/> </p></td> </tr> </table></td> </tr> <tr> <td height='374' valign='top'><strong>N.B Any sales items are non-returnable</strong></td> </tr> </table> "; $subject = "ORDER CONFIRMATION - "; mail($to, $subject, $body, implode("\r\n",$headers)); } //////// } } } } else if (strcmp ($res, "INVALID") == 0) { header('Location: payment-error.php'); } } fclose ($fp); } ?> Thank you all in advance Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/ Share on other sites More sharing options...
princeofpersia Posted March 6, 2012 Author Share Posted March 6, 2012 any help guys? Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324485 Share on other sites More sharing options...
batwimp Posted March 6, 2012 Share Posted March 6, 2012 Are you running your PHP server on a Microsoft box? Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324488 Share on other sites More sharing options...
princeofpersia Posted March 6, 2012 Author Share Posted March 6, 2012 No, its online on a Apache server, why? should i ask hosting company? Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324501 Share on other sites More sharing options...
batwimp Posted March 6, 2012 Share Posted March 6, 2012 Because you can't send an email from a Microsoft server using PHP without implementing some extra code and/or ini setups. You can ask your host, but if you're on apache, you're probably also on a linux box, which should send the email out just fine. I'm just trying to narrow down possibilities. Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324502 Share on other sites More sharing options...
princeofpersia Posted March 6, 2012 Author Share Posted March 6, 2012 yeah i got what you mean now, I can send email, I tested it on a test page, its just this IPN page that wont send anything, so it should be my code. Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324507 Share on other sites More sharing options...
batwimp Posted March 6, 2012 Share Posted March 6, 2012 Have you echoed out your $to, $subject, $body, etc... variables to make sure they are populating correctly? Are you receiving any errors? Do you have error reporting on? Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324515 Share on other sites More sharing options...
princeofpersia Posted March 6, 2012 Author Share Posted March 6, 2012 well its a ipn so i cant echo anything out on that page. how do i get php report on? thanks for your help so far dude Quote Link to comment https://forums.phpfreaks.com/topic/258352-issue-with-ipn/#findComment-1324516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.