做一个邮件发送时我使用了像这样的形式
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,以作记录
来源:oschina
链接:https://my.oschina.net/u/3470006/blog/4813425