Jump to content

Paypal IPN


ultraspoon

Recommended Posts

Hello everyone,

 

Im having some trouble with the IPN script im using, what I need it to do is, when a customer clicks on a buy it now button and completes the payment, it adds their email and a randomly generated password to the database, (that works fine btw) and then finally to send the customer an email with their login details for my site. The code I have has no syntax errors, and I dont believe Im getting any errors anywhere else, but im not sure where to look. Im using the paypal IPN tool for test purposes too.

Can anyone please help me as this is getting quite painful now.

 

Thank you.

 


<?php  
   
mysql_connect("", "", "") or die(mysql_error());  
mysql_select_db("") 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 /';  
$headers = 'From:' . "\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);  
}  
?> 

Link to comment
Share on other sites

Might seem like adding an extra layer, but here goes.

 

The built in "mail" command doesn't authenticate, and can cause mail (when it does work), to end up in peoples junk folders.

 

You can use the following script PHPMailer which uses raw socket connections for full communication with the mail server.  Where mail() has failed, PHPMailer has succeeded with flying colors.  It is also 100% free.

 

Not sure why PHP has not updated their mail() function to allow for such things as authentication, CC, BCC, SSL/TLS, etc, etc, but whatever, this script does everything you need for sending mail --- it even has POP before SMTP authentication.

Link to comment
Share on other sites

After 3 weeks of trying to figure this out, ive finally done it, I had a look into that PHPMailer and thought it would be too much work, and more coading.

 

The problem was this

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);//Test
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);//Live

 

I had my code set to the live version of paypal, not sandbox, I feel so stupid haha.

 

Thanks for your help guys. Thought I would let others know incase they had same issue.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.