du13520157325 2014-02-27 01:59
浏览 31

PHP邮件功能导致错误

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:noreply@yourdomain.com<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>' . "
";

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.

  • 写回答

1条回答 默认 最新

  • dongyou8368 2014-02-27 02:01
    关注

    What is this?

    $headers = 'From:noreply@yourdomain.com<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>' . "
    ";
    

    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:noreply@yourdomain.com';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建