0

I am working on setting up an automated email response via my PayPal IPN Script, however the following code causes paypal's sandbox to fail.

// PAYMENT VALIDATED & VERIFIED!

$email = $_POST['payer_email'];
$password = mt_rand(1000, 9999);

$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 http://yourdomain.com/PayPal/';
$headers = 'From:[email protected]<script type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>' . "\r\n";

mail($to, $subject, $message, $headers);    

Is there something simplistically wrong with it, or is there a deeper cause for the script to cause an error. Keep in mind, i am new to this, and this is code that i copy and pasted from http://code.tutsplus.com/tutorials/using-paypals-instant-payment-notification-with-php--net-3271.

Also, does the from email i use have to be located on the same server i am using to host the script?

the email is removed to avoid giving out personal information.

2
  • Please, please, please do not send any password as plaintext in an email. Commented Feb 27, 2014 at 2:01
  • For reference, the IPN Sandbox does not tell me what the error is, all i know is that it isn't working. Commented Feb 27, 2014 at 2:39

1 Answer 1

2

What is this?

$headers = 'From:[email protected]<script type="text/javascript">
/* <![CDATA[ */
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
</script>' . "\r\n";

You can't have HTML or JavaScript in your mail headers. Take that out ads that is what is probably causing your errors.

$headers = 'From:[email protected]';
Sign up to request clarification or add additional context in comments.

6 Comments

love to know what the op put that there
As i said in my post, i just took the code from a tutorial website. I am not good with PHP. Also, i have no intention of using the password, i just have it there because i never got rid of it. I will try out what you said John.
Update: The above solution allowed the IPN to be successfully sent, but as state in the OP, do i need to have the FROM:Email need to be hosted on the same server?
So the IPN sent successfully, but i have not received any emails. I have one for VERIFIED And INVALID responses from the IPN
There could be lots of reasons for this. Start by trying to send the email from different addresses, some on the server, some not. And to different addresses, some on the server, some not. If you receive some and not others then you know the mail code works. Then search this site for how to keep your mail from getting flagged as spam to improve your delivery rate.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.