June 15, 201016 yr Hey Folks, Ive set up an IPN for my website and tested it through Paypal sandbox, it seems to be working but not completly, the php script I have adds the user to the database and it should also email the buyer their password for the login. The script adds the details to the database but no email is recieved. Here is my ipn.php script. <?php mysql_connect("blank.blank.blank", "blank", "blank") or die(mysql_error()); mysql_select_db("blank") or die(mysql_error()); // 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.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // PAYMENT VALIDATED & VERIFIED! $email = $_POST['payer_email']; $password = mt_rand(1000, 9999); mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error()); $to = $email; $subject = 'Download Area | Login Credentials'; $message = ' Thank you for your purchase Your account information ------------------------- Email: '.$email.' Password: '.$password.' ------------------------- You can now login at blank/'; $headers = 'From:blank' . "\r\n"; mail($to, $subject, $message, $headers); } else if (strcmp ($res, "INVALID") == 0) { // PAYMENT INVALID & INVESTIGATE MANUALY! $email = $_POST['payer_email']; $password = mt_rand(1000, 9999); mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error()); } } fclose ($fp); } ?> Thanks guys.
June 25, 201016 yr Hi there, I'd take a close look at the Headers for sending the email, many email servers will need the 'Reply-To:' paramater set as well as the 'From:'. This can sometimes still not be enough and you may need to set the "envelope sender address" using the -f switch after the headers check the PHP manual fo examples. Steve
June 27, 201016 yr mail($to, $subject, $message, $headers); just try changing it to mail($email, $subject, $message, $headers); also heres some more header stuff! // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: ' . "\r\n"; $headers .= 'From: Clean on the sauce! <Adam@dave.com>' . "\r\n";
Create an account or sign in to comment