【问题标题】:Email sending error in Codeigniter " fwrite(): send of 6 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host."Codeigniter 中的电子邮件发送错误“ fwrite(): send of 6 bytes failed with errno=10054 现有连接被远程主机强行关闭。”
【发布时间】:2021-06-19 13:11:59
【问题描述】:

想处理发送邮件时 smtp 主机服务器重启的情况。发送脚本的电子邮件不应因运行时错误而终止。它应该尝试重新连接到服务器主机并再次发送电子邮件

我的代码:

$config=array('protocol'=>'smtp',
                'smtp_host'=>'example.com',     
                'smtp_port'=>587,
                'smtp_user'=>'******',
                'smtp_pass'=>'***', 
                'priority'=> 1,
                'smtp_timeout'=>'30',
                //'smtp_keepalive'=>TRUE,
                'mailtype'  => 'html',              
                'charset'=>'utf-8',
                'wordwrap'=>True);  
 foreach($res2 as $email)
{
  $this->email->from($fromemail,$fromname);
                
                $this->email->to($email);              
                $this->email->subject('Dummy Email');               
                $body=$emailDesign2;
                $this->email->message($body);
                
                
                
                
                                
                    if($this->email->send())
                    {
                        echo "Mail Sent<br/>";
                        $total++;
                    }
                    else
                    {
                         echo "Mail Not Sent";
                    }

}

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    尝试创建一个函数,当发送失败时再次调用该函数。

    function send_email($class, $details){
    
        $total = 0;
    
        $class->from($details['fromemail'], $details['fromname']);
                    
        $class->to($details['email']);              
        $class->subject('Dummy Email');               
        $body = $datails['body'];
        $class->message($body);
                    
        if($class->send()) {
            echo "Mail Sent<br/>";
            $total++;
        } else {
           send_email($class, $details);
        }
    
        return $total;
    }
    
    foreach($res2 as $email) {
        // Return the number of success emails
        $total = send_email($this->email, array(
            'email' => $email,
            'fromemail' => $fromemail,
            'fromname' => $fromname,
            'body' => $emailDesign2
        ));
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      相关资源
      最近更新 更多