PHP:PEAR电子邮件仅在第二次传递时发送

时间:2013-08-12 09:42:54

标签: php pear

我正在使用pear通过以下代码发送电子邮件,这是我第一次遇到此错误:

  

“无法设置发件人:aa@bb.com [SMTP:收到的响应代码无效   来自服务器(代码:-1,响应:)]“

如果我在发送后调试并将执行点设置回'从这里重新运行',它运行正常 - 几乎就像第一次没有正确初始化的东西 - 任何人对此都有任何想法?

require_once "Mail.php";

function SendEMail() {

     $from = "Sender Sender <sender@example.com>";
     $to = "AA BB <aa@bb.com>";
     $subject = "Test";
     $body = "This is a test";

     $host = "myhost";

     $headers = array ('From' => $from,
                        'To' => $to,
                        'Subject' => $subject);

     //Re-run from here        
     $smtp =& Mail::factory('smtp',
       array ('host' => $host,
         'auth' => false,
         'username' => '',
         'password' => ''));

     $mail = $smtp->send($to, $headers, $body);

     if (PEAR::isError($mail)) {
        $s = $mail->getMessage();
     }
 } 

1 个答案:

答案 0 :(得分:0)

使用wireshark找出您真正从服务器获得的响应。也许服务器已激活灰名单,因此您无法在第一时间发送邮件。