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

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

Related

Sent email with iCal to outlook with valarm reminder

I am in a situation where I want to send email with iCal attachment to Outlook Calendar and I want to set reminder to 120 minutes before start event.
I send RAW message with iCal(see below).
If recipient opens the message, event is automatically added to outlook calendar, but reminder is set to 15 minutes(default in outlook), even if I set different value in VALARM.
If I use ics file with iCal to import to Outlook Calendar then reminder is set to my value.
I would really appreciate help on this. How to set reminder for event?
$from_name = "<FROM_NAME>";
$from_address = "<FROM_ADDRESS>";
$subject = "Meeting Booking";
$meeting_description = "Here is a brief description of my meeting\n\n";
$meeting_location = "My Office";
$domain = 'domain.com';
$to_name = "<TO_NAME>";
$to_address = "<TO_ADDRESS>";
$meeting_date = "2015-10-21 15:40:00";
$meeting_duration = 3600;
$meeting_stamp = STRTOTIME($meeting_date . " UTC");
$dtstart= GMDATE("Ymd\THis\Z",$meeting_stamp);
$dtend= GMDATE("Ymd\THis\Z",$meeting_stamp+$meeting_duration);
$mime_boundary = "----Meeting Booking----".MD5(TIME());
//Create ICAL Content
$ical = 'BEGIN:VCALENDAR' . "\r\n" .
'PRODID:-//Patient Portal//MyEyeDr.//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($meeting_date)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="America/New_York":'.$dtstart. "\r\n" .
'DTEND;TZID="EAmerica/New_York":'.$dtend. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $meeting_location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM'. "\r\n" .
'ACTION:Display'. "\r\n" .
'DESCRIPTION:'.$meeting_description. "\r\n" .
'SUMMARY:Event Alarm'. "\r\n" .
'TRIGGER:-PT120M'. "\r\n" .
'END:VALARM'. "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
$message= "To: ".$to_address."\n";
$message.= "From: ".$from_address."\n";
$message.= "Subject: Example SES mail (raw)\n";
$message.= "MIME-Version: 1.0\n";
$message .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$message .= "Content-class: urn:content-classes:calendarmessage\n";
$message.= "\n\n";
$message .= "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear ...,</p>';
$message .= '<p>This is an email message.</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST'."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "X-Mailer: Microsoft Office Outlook 15.0\r\n";
$message .= $ical;
I think there is nothing wrong with your code. Most calendar clients will ignore any alarm that is sent along with an invitation. When you think about it, this makes sense: if you invite me, I may want to accept or decline, but you should not dictate when I want to be notified.
On the other hand, when importing, you are making those events your own.
Change METHOD:REQUEST to METHOD:PUBLISH. Also change your other method code at the bottom from method=REQUEST to method=PUBLISH.

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

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 :)

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.

php mail with PDF attachment header causes to go into just mail

I have a webform that generates a PDF which is emailed to me upon submission but the email keeps getting filtered to the spam for folder. I suspect that the something is wrong in the email header but not sure what it could be.
Any help is appreciated.
The following is a snippet...
// send by email
$fileatt = '../pdfs/'.$filename;
$fileatt_type = mime_content_type_manual($fileatt); // File Type "application/pdf"
$fileatt_name = $filename; // Filename that will be used for the file as the attachment
$email_from = "auth#mysite.com"; // Who the email is from
$email_subject = "Auth Report"; // The Subject of the email
//$email_to = "info#mysite.com";
$email_to = "info#mysite.com";
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
If you add the sender of the email, which is auth#mysite.com for your case, as a new contact to the address book of your email client, then the email won't probably be marked as spam as it comes from a member of your contact address book.

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);