PHPMailer6.2 MAIL FROM command failed異常的一個原因

做一個郵件發送時我使用了像這樣的形式

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,以作記錄

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章