php PHPMailer SMTP 配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14256582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:57:42  来源:igfitidea点击:

PHPMailer SMTP configuration

emailphpmailerphp

提问by woutr_be

For the past 2 hours I've been looking online to see if any other people encountered this problem, and it seems a lot has, bot none of the answers are working for me.

在过去的 2 个小时里,我一直在网上查看是否有其他人遇到过这个问题,似乎有很多人遇到过,没有一个答案对我有用。

SMTP -> FROM SERVER:220 mx.google.com ESMTP vq7sm928004oeb.13 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.57.114.141] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250 ENHANCEDSTATUSCODES 
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.57.114.141] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES 
SMTP -> FROM SERVER:530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 vq7sm928004oeb.13 
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 vq7sm928004oeb.13 
The following From address failed: [email protected]

$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMPTAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 587;
$mail->Username = "[email protected]";
$mail->Password = "password";

I've tried almost every setting for PHPMailer, but can't figure out what's still going wrong, are there any server settings I need to take care of?

我已经尝试了 PHPMailer 的几乎所有设置,但不知道哪里出了问题,我需要处理任何服务器设置吗?

I also tried the normal php mail() function, but that's not sending mail either, although when using Drupal forms it just sends an email.

我还尝试了普通的 php mail() 函数,但这也不是发送邮件,尽管在使用 Drupal 表单时它只是发送了一封电子邮件。

采纳答案by woutr_be

Just noticed I typed SMTP wrong in this line $mail->SMPTAuth = true;, correcting this solved my problem.

刚刚注意到我在这一行中输入了错误的 SMTP $mail->SMPTAuth = true;,纠正这个问题解决了我的问题。

回答by kingmo

For first you must configure the correct server to send emails (see at gmail.com):

首先,您必须配置正确的服务器才能发送电子邮件(请参阅 gmail.com):

SMTP server address: smtp.gmail.com
SMTP user name: Your full Gmail address (e.g. [email protected])
SMTP password: Your Gmail password
SMTP port: 465 or 587
SMTP TLS/SSL required: yes

In PHPMailer:

在 PHPMailer 中:

$mail->SMTPAuth = true; // There was a syntax error here (SMPTAuth)
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 465;
$mail->Username = "[email protected]";
$mail->Password = "YOUR_GMAIL_password";

回答by Mike Gifford

My problem was that I use the 2-step verification. So I had to remember to go to Authorised Access for my Google Account & then assign a Application-specific passwords for the domain that I'm using to send the mail.

我的问题是我使用了两步验证。因此,我必须记住转到我的 Google 帐户的授权访问,然后为我用来发送邮件的域分配特定于应用程序的密码。

回答by Patrick van Efferen

Setting up mail in php can be quite hard. have you tried using port=25?

在 php 中设置邮件可能非常困难。你试过使用 port=25 吗?

回答by Smittie

The suggested port+protocol-combination seems wrong to me, because it's different to the official phpMailer-wiki:

建议的 port+protocol-combination 对我来说似乎是错误的,因为它与官方的phpMailer-wiki 不同

Don't mix up these modes; ssl on port 587 or tls on port 465 will not work.

不要混淆这些模式;端口 587 上的 ssl 或端口 465 上的 tls 将不起作用。

In PHPMailer:

在 PHPMailer 中:

$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->Port = 587; //use port 465 when using SMPTSecure = 'ssl'
$mail->Username = "[email protected]";
$mail->Password = "YOUR_GMAIL_password";