无法通过 gmail 从新创建的电子邮件中使用 phpMailer 发送 SMTP 邮件 [重复]
Posted
技术标签:
【中文标题】无法通过 gmail 从新创建的电子邮件中使用 phpMailer 发送 SMTP 邮件 [重复]【英文标题】:Unable to send SMPT mails using phpMailer from a newly created email via gmail [duplicate] 【发布时间】:2016-03-24 20:21:17 【问题描述】:当我使用自己的电子邮件地址时,我的电子邮件正在工作,但我需要使用网站新创建的电子邮件来运行它。此电子邮件是使用 gmail 创建的。
这是我的代码:
function phpMailer($emailTo, $subject, $body)
$email_temp = $body;
$to = $emailTo;
Yii::import('application.extensions.phpmailer.JPhpMailer');
$mail = new JPhpMailer;
$mail->IsSMTP();
//$mail->Host = 'smtp.googlemail.com:465';
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = "tls";
$mail->Port = 587;//465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = true;
$mail->Username = 'info@domainname.com';
$mail->Password = 'xxxxxxxx';
$mail->SetFrom('info@domainname.com', 'domainname'); //Send 'From' User
$mail->Subject = $subject;
$mail->AltBody = $email_temp;
$mail->Msghtml($email_temp); // message /template
$mail->AddAddress($to); //Send mail 'To' User
//check if mail sent successfully
if($mail->Send())
return true;
return false;
我在使用代码 2 进行调试时收到以下响应。
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP c3sm6277150qge.12 - gsmtp "
SMTP -> get_lines(): $data is "220 smtp.gmail.com ESMTP c3sm6277150qge.12 - gsmtp "
SMTP -> FROM SERVER:220 smtp.gmail.com ESMTP c3sm6277150qge.12 - gsmtp
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [54.209.41.153] "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] "
SMTP -> get_lines(): $str is "250-SIZE 35882577 "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME "
SMTP -> get_lines(): $str is "250-STARTTLS "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING "
SMTP -> get_lines(): $str is "250-CHUNKING "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING "
SMTP -> get_lines(): $str is "250 SMTPUTF8 "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 "
SMTP -> FROM SERVER: 250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS "
SMTP -> get_lines(): $data is "220 2.0.0 Ready to start TLS "
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [54.209.41.153] "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] "
SMTP -> get_lines(): $str is "250-SIZE 35882577 "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 "
SMTP -> get_lines(): $str is "250-8BITMIME "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME "
SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH "
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES "
SMTP -> get_lines(): $str is "250-PIPELINING "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING "
SMTP -> get_lines(): $str is "250-CHUNKING "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING "
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING "
SMTP -> get_lines(): $str is "250 SMTPUTF8 "
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 "
SMTP -> FROM SERVER: 250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 "
SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6 "
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 "
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 "
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "534-5.7.14 SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 w1qusykfYpU2yVqlT4ZEIFrXPep3JwRh3FfzQc7ddey5QQmBd4JbZi9tNFSnBFHW7IdOcx "
SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 NbZA5LEBoeSZEcjcwhBW_Kfziy5pHrZal2opZ3uBdoF-WM4OPoMDnfG_w_7fNOtjA8HGPw "
SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 zL0OcSfQMG3sJ1fwVuYZTRL3prN6EZudpmCgygKIv1lqW9r7w8fXC5v-3qGXWP3PxghHp8 "
SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 fVgbNTqeHZhv728Su3O-QGwFNdsU> Please log in via your web browser and "
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and "
SMTP -> get_lines(): $data was "534-5.7.14 Please log in via your web browser and "
SMTP -> get_lines(): $str is "534-5.7.14 then try again. "
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. "
SMTP -> get_lines(): $data was "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. "
SMTP -> get_lines(): $str is "534-5.7.14 Learn more at "
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at "
SMTP -> get_lines(): $data was "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at "
SMTP -> get_lines(): $str is "534 5.7.14 https://support.google.com/mail/answer/78754 c3sm6277150qge.12 - gsmtp "
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c3sm6277150qge.12 - gsmtp "
SMTP -> ERROR: Password not accepted from server: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c3sm6277150qge.12 - gsmtp
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "250 2.1.5 Flushed c3sm6277150qge.12 - gsmtp "
SMTP -> get_lines(): $data is "250 2.1.5 Flushed c3sm6277150qge.12 - gsmtp "
SMTP -> FROM SERVER:250 2.1.5 Flushed c3sm6277150qge.12 - gsmtp
SMTP Error: Could not authenticate.
【问题讨论】:
请阅读您的错误消息,告诉您转到here。您正在运行旧版本的 PHPMailer,并且您的代码基于一个早已过时的示例。这个问题有数百个重复项,the docs 对此进行了广泛的讨论。真的,你只是没有尝试。 @Synchro:直到现在我才真正使用自己的 gmail 电子邮件,而且邮件工作正常。今天我实施了他为他的网站购买的客户电子邮件,并且邮件停止工作。当我调试时,我收到上述消息。问题根本不在代码中。这是因为谷歌的电子邮件设置更安全。 【参考方案1】:我找到了解决这个问题的方法。您需要强制从链接访问不太安全的应用程序。 less secure apps setting 或者如果您已经从 google 邮件应用程序配置了电子邮件,请转到 admin->security->basic setting 并执行上述操作。
【讨论】:
以上是关于无法通过 gmail 从新创建的电子邮件中使用 phpMailer 发送 SMTP 邮件 [重复]的主要内容,如果未能解决你的问题,请参考以下文章
通过 Gmail REST API 发送的电子邮件/草稿无法在新的 Gmail 用户界面中打开
无法使用 xampp 从 gmail 发送邮件(使用 php 脚本)
无法使用 gmail 通过 python 发送电子邮件 - smtplib.SMTPException:服务器不支持 SMTP AUTH 扩展