以下“发件人"地址失败,但未连接,但调用了Mail()
大家好,我收到此错误:
Hello guys I get this error:
以下发件人地址失败:username_from@gmail.com:未连接就调用Mail()
The following From address failed: username_from@gmail.com : Called Mail() without being connected
<?php
require("PHPMailer/class.phpmailer.php");
$msg = 'hello world!';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'username@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'username_from@gmail.com';
$mail->FromName = 'My name';
$mail->AddAddress('other_user@gmail.com', '');
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = 'hello';
$mail->Body = $msg;
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
?>
我该如何解决?谢谢!我使用Gmail邮件服务器从在PHP中运行XAMPP的本地主机发送电子邮件.
How can I fix it? Thanks! I send email from localhost running XAMPP in PHP using Gmail mail server.
可能的错误原因:
-
您必须编辑您的gmail帐户权限.尝试启用访问不太安全的应用程序"的安全性"设置.
you have to edit your gmail account permissions. Trying enabling the 'Access for less secure apps' Security setting.
可能是,您正在使用旧版本的PHPMailer-更新它.
may be,you're using an old version of PHPMailer - update it.
请勿将ssl/465用于gmail;使用tls/587.看看 gmail示例代码与PHPMailer一起提供.
Don't use ssl/465 for gmail; use tls/587. Take a look at the gmail example code provided with PHPMailer.