我想用Gmail的smtp发送电子邮件(见下面的代码),但我得到“用户名和密码不被接受”的错误。用户名和密码不被接受
我已经试过:
this link
allow less secure apps
- 启用SSL
- 启用IMAP/POP Gmail的设置
- 不同的登录
没有的他们的作品。
这里是PHP代码:
function sendEmail($from, $fromName, $msg)
{
$mail = new PHPMailer();
$mail->SMTPDebug = 4; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$mail->IsSMTP();
//$mail->Host = 'tls://smtp.gmail.com:587';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; //465
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'yyyyyyy';
$mail->From = $from;
$mail->FromName = $fromName;
$mail->AddAddress('[email protected]', ' ');
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Priority = 1;
$mail->Timeout = 60;
$mail->SMTPKeepAlive = true;
$mail->Subject = "subject here";
$mail->Body = $msg;
$mail->AltBody = 'testing..';
$ok = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
return $ok;
}
更新:Here's
完整的错误消息(与DebugMode = 4)
您是否使用新创建的Gmail帐户?在某些时候,谷歌增加了有关如何使用Gmail帐户的限制smtp – 2015-02-11 19:08:54
@MichaelColeman:该帐户约1年。我在哪里可以找到关于这些新限制的更多信息? – Jack 2015-02-11 19:10:47
尝试创建一个应用密码而不是使用您的Gmail,https://security.google.com/settings/security/apppasswords过去为我工作。 – 2015-02-11 19:13:07