Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

IPN and PHP

Featured Replies

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.

  • 2 weeks later...

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

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.