Codeigniter“fwrite()”中的电子邮件发送错误:发送6个字节失败,errno=10054远程主机强制关闭了现有连接,”

9nvpjoqh  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(152)

希望处理在发送电子邮件时重新启动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";
                    }

}
tpgth1q7

tpgth1q71#

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

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

ruoxqz4g2#

请看谷歌应用程序密码服务...因为在谷歌帐户设置中,2步身份验证将被激活,我的codeignitor设置已经成功工作,设置是这样的...

"protocol"   => "smtp",
    "smtp_host"  => "ssl://smtp.gmail.com",
    "smtp_port"  => "465",
    "smtp_timeout"  => "7",
    "smtp_user"  => $email_settings->user_email,
    "smtp_pass"  => "xxxxxxx", // please take this from google app password services...
    "starttls"   => TRUE,
    "charset"    => "utf-8",
    "mailtype"   => "html", // or text/plain
    "wordwrap"   => TRUE,
    "newline"    => "\r\n",
    "validate"    => FALSE,
    "smtp_keep_alive"    => TRUE

还有其他字段,如发件人、收件人、主题和消息...
感谢您的好意,为您的关注和兴趣....

相关问题