做一個郵件發送時我使用了像這樣的形式
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,以作記錄