PHPMailer6.2 MAIL FROM command failed异常的一个原因

佐手、 提交于 2020-12-17 19:28:53

做一个邮件发送时我使用了像这样的形式

class a{
    private $PHPMailer;
    public function __construct()
    {
        $this->PHPMailer=new \PHPMailer\PHPMailer\PHPMailer();
    }
    private function getSender(){
        return '返回一个可用的发送者';
    }
    private function sendMail($Address, $Title, $Content)
    {
        $Sender = $this->getSender();
        $this->PHPMailer=new PHPMailer\PHPMailer\PHPMailer(true);
        $this->PHPMailer->Host = $Sender['Host'];
        $this->PHPMailer->Username = $Sender['Address'];
        $this->PHPMailer->Password = $Sender['AuthCode'];
        $this->PHPMailer->SMTPAuth = true;
        $this->PHPMailer->CharSet = 'utf-8';
        $this->PHPMailer->Subject = $Title;
        $this->PHPMailer->Body = $Content;
        $this->PHPMailer->isSMTP();
        $this->PHPMailer->setFrom($Sender['Address']);
        $this->PHPMailer->addAddress($Address);
        $this->PHPMailer->send();
    }
}

本想一次实例化还能提高些性能的,getsender()每次会返回一个随机的发送者,但当多次调用sendMail函数到第三次时会产生"MAIL FROM command failed,Mail from must equal authorized user ,553,SMTP server error: MAIL FROM comm"这样的异常

将实例化改成sendMailli每次都实例化就好了,这可能是6.2版本的一个bug,以作记录

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!