Connection timed out with IPN call especially for sandbox.paypal.com - paypal

Following is the sample code:
$req = "122";
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Connection: close\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);
if(!$errno)
{
var_dump($fp);
}
else
{
echo "ERROR: $errno, $errstr";
}
When I connect to the sandbox it produces me a connection timed out error:
ERROR: 110, Connection timed out
So I debugged the problem and found out it was something to do with the SSL and verified the existence and accessibility of openssl in the server.
Tested the openssl and connectivity on the server with the following
"openssl s_client -connect www.sandbox.paypal.com:443"
I get
"Socket: Connection Timed out"
I checked out iptables and there is no blocking for port 443
So I tried again to check the case for paypal.com, like the following:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
It worked immediately.
So I tried in my other server and I was able to connect to sandbox.paypal.com but not on the server where I need to demo and test payments.
My hosting provider is clueless and I am pulling my hair out here.
I appreciate any help on this.
Yes, ofcourse my first question on Stackoverflow :)

Related

Buy subscription with paypal through IPN, paypal response slower than buy item with no subscription

I'm having a problem with IPN paypal response. I'm using cmd = '_xclick-subscriptions';
And code to post back paypal is:
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.sandbox.paypal.com\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);
But after done payment, I must wait sometime to 2 or 3 mins to paypal response to update my database.
I can't understand about this problem. Any ideas to help me, please.
P/s: my domain is: http://ecomdev.sitelantern.com
Thanks

PayPal sandbox ipn status never verified

I'm testing a PayPal ipn listener and it seems it NEVER returns VERIFIED status... Here's the script :
<?php
//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.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host:www.sandbox.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//
//error connecting to paypal
if (!$fp) {
//
}
//successful connection
if ($fp) {
fputs ($fp, $header . $req);
//while (!feof($fp)) {
$res = stream_get_contents($fp, 1024);
//$res = fgets ($fp, 1024);
$res = trim($res); //NEW & IMPORTANT
if (strcmp($res, "VERIFIED") == 0) {
// if status is COMPLETED insert order into database
if ($_POST['payment_status'] == "Completed") {
$subject = 'Instant Payment Notification - COMPLETED';
$to = 'my_email_address#gmail.com'; // your email
$body = "An instant payment notification was successfully recieved\n";
$body .= "from ".$_POST['payer_email']." on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\nDetails:\n";
foreach ($_POST as $key => $value) { $body .= "\n".$key." : ".$value; }
mail($to, $subject, $body);
}
}
else {
//insert into DB in a table for bad payments for you to process later
$subject = 'Instant Payment Notification - ELSE status';
$to = 'my_email_address#gmail.com'; // your email
$body = "Else clause \n";
$body .= "from ".$_POST['payer_email']." on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\nDetails:\n";
foreach ($_POST as $key => $value) { $body .= "\n".$key." : ".$value; }
mail($to, $subject, $body);
}
//}
fclose($fp);
}
?>
I've tried the code with while (!feof($fp)) and $res = fgets ($fp, 1024)
I never get the VERIFIED email and I'm even not sure if it is a coding issue... That's why I'm asking here : maybe some of you had this problem before and can help me. Thanks in advance.
OK, here is the $res posted back :
HTTP/1.1 200 OK
Date: Wed, 26 Feb 2014 12:03:23 GMT
Server: Apache
domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Sat, 24-Feb-2024 12:03:24 GMT;domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Fri, 26-Feb-2016 12:03:24 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.72.109.11.1393416203743713; path=/; expires=Fri, 19-Feb-44 12:03:

Why did Implementing HTTP/1.1 break my IPN script?

Here is the original code I had in my PHP script:
$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";
I got an email from Paypal saying that I needed to upgrade my IPN script so that it uses HTTP/1.1. So here is what I changed my code to, based on their directions:
$header .="POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .="Content-Type: application/x-www-form-urlencoded\r\n";
$header .="Host: www.paypal.com\r\n";
$header .="Connection: close\r\n";
Payments have gone through today, but the IPN is no longer updating my database and this is the only change I made to it. Any ideas on what to do?
Thanks!
Yes. I have just done battle with this. What worked for me was to remove the connection close header, and add a trim to the response back from PP. Here are the headers:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
Here is the fsockopen:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
and here is the trim on the response back from PP:
if (!$fp) {
// HTTP ERROR
error_mail("Could not open socket");
//
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = trim(fgets ($fp, 1024));
}
//
// check the payment_status is Completed
// check that receiver_email is your Primary PayPal email
//
if ((strcmp ($res, "VERIFIED") == 0) && ($payment_status == "Completed") && ($receiver_email == $valid_receiver_email)) {
That worked for me.

Change the Return-Path in PHP mail function

Is it possible to change the Return-Path value in emails are sending via mail() function of PHP ?
It's value is 'www-data#mydomain.com' in emails I send in my site and it causes some problems on email delivery failed process. I want to set it to my email address.
Here's the code I have tried:
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\n";
$headers .= "Return-Path: <adminemail#yahoo.com>"."\n";
$headers .= "Errors-To: <adminemail#yahoo.com>"."\n";
// Additional headers
$headers .= "To: email1#yahoo.com <adminemail#yahoo.com>" . "\n";
$headers .= "From: adminemail#yahoo.com <adminemail#yahoo.com>";
// Mail it
mail('email1#yahoo.com', 'test', 'salam', $headers, "f");
You can set reply to & return path into headers as below
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'Return-Path: webmaster#example.com'
OR
as the fifth parameter to adjust the return path
mail($to, $subject, $message, $headers, "-f email#wherever.com");
where email#wherever.com should be replaced by your mail.
The issue is mail format requires headers to use \r\n line endings... not \n, the trick with that is some servers will accept both (convert them for you and it seems to work magically) while others will consider those without \r\n endings to be invalid and basically ignore all your headers. So try instead:
$headers = "MIME-Version: 1.0\r\n".
"Content-type: text/html; charset=utf-8\r\n".
"Return-Path: adminemail#yahoo.com";
mail ("email1#yahoo.com","test","salam",$headers);
By the way, return-path expects an RFC1123 mailbox (without the angle brackets, just the email address) ... not sure why you'd want to set return-path as in your example since it's the same as the from address (so superfluous)
Just define Return-Path
$returnPath = "-fadminemail#yahoo.com"; //-f will do the job
mail('email1#yahoo.com', 'test', 'salam', $headers, $returnPath);

Warning: mail() [function.mail]: SMTP server response: 552 5.7.0 DATA header size exceeds maximum permitted

I'm Beau from Fijura Web Design in Perth, Western Australia.
Having an issue on my server. I am trying to create a script that will send an email with an attachment and whenever I try to run the script I get the following response:
Warning: mail() [function.mail]: SMTP server response: 552 5.7.0 DATA
header size exceeds maximum permitted in E:\folder\folder\_api\sendreports.php
on line 52
The code I am using is a proven script as I use it on shared Linux servers at our data centre but I cannot get it to work on my Windows server. The script I use is:
include "../reports/rankings.php"; //this is my FPDF attachment
$to=$array['email']; //this pulls an email address from an array output by my MySQL Server
$from="Fijura SEO<seo#fijura.com.au>";
$subject="SEO Ranking Report - New Data ".date("d M Y");
$message="New SEO data is available. See attached report.";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "SEO-Ranking-Report-".date("d-M-Y").".pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header (multipart mandatory)
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; //If I remove all $header information from this line down the email sends fine, just without the attachment.
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
mail($to,$subject,$message,$headers) or die("Failed");
The attached PDF should look like this: Sample SEO Rankings Report
also the php.ini file is configured as follows:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.bigpond.com
; http://php.net/smtp-port
smtp_port = 25
I guess your email will be come back.I have 3 recommendation:
1. Read careful The Spamhaus Project that it cause your emails aren't spam.
2. create an *.eml and send it via socket. your .eml contain of your email such as type of header,body, attachment and etc.
3. don't use mail() function of php language, because some of shared hosting ban it.