我使用PHPMailer发送电子邮件,但有时会失败。
$email = new \PHPMailer();
$email->isSMTP();
$email->Host = 'smtp.gmail.com';
$email->SMTPAuth = true;
$email->Username = '...';
$email->Password = '...';
$email->SMTPSecure = 'tls';
$email->Port = 25;
$email->From = '...';
$email->FromName = '...';
$email->Subject = '...';
$email->addAddress( '' );
$email->Body = '...';
$email->isHTML( true );
if ( !$email->send() ) {
echo $email->ErrorInfo;
}
我收到The following From address failed: ... : Called Mail() without being connected
错误。
注意,有时它会成功,有时则不会。