使用 Gmail 帐户的 XAMPP Sendmail
我正在尝试通过 XAMPP 配置 Sendmail 来发送电子邮件。在我的 sendmail.ini 中,我有以下设置:
# Set default values for all following accounts.
logfile "C:\xampp\sendmail\sendmail.log
account Gmail
tls on
port 587
tls_certcheck off
host smtp.gmail.com
from [email protected]
auth on
user [email protected]
password mypassword
account default : Gmail
我创建了一个这样的测试脚本:
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: [email protected]" . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo ("Message successfully sent!");
} else {
echo ("Message delivery failed...");
}
我收到一条消息,说电子邮件已发送,但它从未到达,并且在日志中我得到:
sendmail: 传递期间错误: 必须发出首先是 STARTTLS 命令。
有人知道这里可能出现什么问题吗?
提前致谢!
天然气
I'm trying to configure Sendmail through XAMPP to send email. In my sendmail.ini I have these settings:
# Set default values for all following accounts.
logfile "C:\xampp\sendmail\sendmail.log
account Gmail
tls on
port 587
tls_certcheck off
host smtp.gmail.com
from [email protected]
auth on
user [email protected]
password mypassword
account default : Gmail
I've created a test script like this:
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: [email protected]" . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo ("Message successfully sent!");
} else {
echo ("Message delivery failed...");
}
I get a message to say that the email was sent but it never arrives and in the logs I get:
sendmail: Error during delivery: Must issue a STARTTLS command first.
Does anybody know what the issue could be here?
Thanks in advance!
Gaz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
这对我有用,希望没有人会像我一样费力地解决这个问题。
这是我的sendmail.ini
php/php.ini ----基本上注释掉了除了sendmail_path & 之外的所有内容。 mail.add_x_header
在我更新了 sendmail 文件(旧的不支持 smtp)后,这对我有用,
当我遇到这个问题时,我正在本地主机上制作密码恢复 php。我需要向用户发送密码。
- 你的 php 看起来没问题
This is what worked for me Hopefully no one else will burn oil to figure this out like i did.
Here is my sendmail.ini
php/php.ini ----basically comment everything out except sendmail_path & mail.add_x_header
This worked for me after i updated the sendmail files (the old ones dont support smtp)
I was making a password recovery php on localhost when i encountered this problem. I needed to send users their password.
- your php looks okey
好吧,今天,最佳答案对我不起作用。但是,这样做了:
在sendmail.ini中:
在php.ini:中
基于端口@:http://support.google.com/mail/bin/answer.py?hl=zh-CN&answer=13287
Okay, today, the best answer did not work for me. But, this did:
in sendmail.ini:
in php.ini:
Based on port @: http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
我所要做的就是将“允许安全性较低的应用程序访问您的帐户”切换为打开状态。我想这是创建应用程序特定密码的替代方法。
https://support.google.com/accounts/answer/6010255了解信息
https://www.google.com/settings/security/lesssecureapps 进行切换
可能值得出于安全目的,完成后将其关闭。
All I had to do was switch the "Allow less secure apps to access your account" to on. I guess this is an alternative to creating an app specific password.
https://support.google.com/accounts/answer/6010255 for info
https://www.google.com/settings/security/lesssecureapps for the switch
Might be worth switching it back off after you're done for security purposes.
使用 Gmail 时还有另一个问题。 Gmail 现在具有安全性,因此您必须生成应用程序专用密码 - 您无法使用您拥有的密码进行正常的 Gmail 访问。我通过尝试上面的示例发现了这一点,然后注意到在 sendmail 文件夹中生成了错误日志。在错误日志中,我发现一条消息表明了这一点。
There is another issue when using Gmail. Gmail now has security so that you must generate an application specific password - you can't use the password you have for your normal Gmail access. I discovered this by trying the examples above and then noticing that in the sendmail folder an error log had been generated. In the error log I came across a message indicating this.
以下是最新的 Google SMTP 服务器要求:
Google SMTP 要求
如果您只使用 SSL,则所需的验证码验证测试会变得复杂所以我只是将 SSL 设置为自动,当 SSL 失败时,它将尝试 TLS。
These are the most recent Google SMTP server requirements:
Google SMTP Requirements
If you just use SSL it gets complicated with the required Captcha verification test so I just set my SSL to auto which will try TLS when SSL Fails.
只是为了补充已经很好的回应。确保您以管理员身份运行 XAMPP。这就是为我解决的问题。
Just to add to the already great responses. Make sure you are running XAMPP as Administrator. That was what fixed it for me.
我找不到完整的工作解决方案,因此我在这里编译它,以供我们参考来源 https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/#
您还没有完成!最后要做的一件事是获取应用程序密码
而不是您的 Gmail 帐户密码,如下所示:
在浏览器上登录您的 Gmail 帐户,然后单击右上角的个人资料图标,选择
,左栏点击安全,找到框
点击
,这里需要为这个xampp下发送邮件创建一个密码
生成密码并将生成的密码复制到
就是这样,一切都完成了,现在应该对你有用了!
祝您邮件愉快!
I could not find a complete working solution so I compile it here for us some credit to source https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/#
You are not done yet! 1 last thing to do is getting application password
and not your gmail account password as the following:
On a browser login your gmail account, then click on your profile icon top right, select
, the on the left column click on security, find box
click on
, here you need to create a password for this xampp send mail under
generate a password and copy the the generated password to
That is it, all done, it should work for you now!
Enjoy your mails!
a) 更改 php.ini
在文件路径“[驱动器号]:[XAMPP 目录]\php”中找到 php.ini。例如 C:\xampp\php\php.ini
在 php.ini 文件中搜索
sendmail_path
并删除分号“;”在它之前[我的没有路径]。b) 更改sendmail.ini
在文件路径中找到sendmail.ini“[驱动器盘符]:[XAMPP目录]\sendmail”,例如C:\xampp\sendmail\sendmail.ini
将“Mercury”和“A free mail service example”内容注释为
如下图所示:
c.添加 Gmail 帐户。
示例:
d.重新启动 Apache 服务器
我没有使用 gmail。我使用了我的托管帐户。如果您这样做,请确保 SMTP 设置正确。我的是mail.abc.com而不是smtp.gmail.com。
此代码来自 2 个网站。您需要更改这两个文件。
我让它在 win200sp4 机器上运行的 Xampp 1.73 上运行。除了这两个文件之外的所有默认设置。 php.ini 和 sendmail.ini
a) Change php.ini
Locate php.ini in file path “[Drive Letter]:[XAMPP directory]\php”. e.g. C:\xampp\php\php.ini
Search for
sendmail_path
in your php.ini file and remove the semi colon “;” before it [mine did not have path].b) Change sendmail.ini
Locate sendmail.ini in file path is “[Drive Letter]:[XAMPP directory]\sendmail” e.g. C:\xampp\sendmail\sendmail.ini
Comment the “Mercury” and “A free mail service example” contents as
shown below:
c. Add the gmail account.
Example:
d. Restart Apache Server
I did not use gmail. I used my hosting account. If you do that, make sure the SMTP settings are correct. Mine was mail.abc.com not smtp.gmail.com.
This code is from 2 websites. You need to change both files.
I have it working on Xampp 1.73 running on a win200sp4 box. All default setting except for these two files. php.ini and sendmail.ini
2020 年更新
简化的解决方案:
如果您使用 Gmail,则可以设置应用程序专用密码。
这个解决方案对我有用,但当然可能还有其他错误阻止您成功,例如更新 xampp/sendmail 文件夹中的文件、正确的端口设置等。
Update for 2020
Simplified solution:
If you are using Gmail you can set an application specific password.
This solution worked for me, but off course there may be other errors blocking your success here, like updating the files in the xampp/sendmail folder, correct port settings etc.
第 1 步:转到您的 sendmai.ini
A. 设置您的 smtp 服务器名称。因为我使用 gmail,所以对我来说它是“smtp.gmail.com”
B. 设置您的 SMTP 端口号。对于 gmail,您可以使用“465”
C。最重要的部分是现在。设置密码。您必须生成应用程序密码才能从服务器发送电子邮件。为此,请按照链接中的步骤操作。 *** 不要使用您的 Gmail 登录密码。这是行不通的。您必须生成应用程序密码。如果您启用了两步验证,请按照以下步骤生成应用程序密码,否则只需使用您的 Gmail 密码。
https://devanswers.co/create-application-specific-password-gmail/
步骤 2:转到 php.ini
A. 相应地设置 SMTP 和 smtp_port 的值。保存并不要忘记重新启动 apache。
Step 1: Go to your sendmai.ini
A.Set your smtpserver name. As i use gmail so for me it is "smtp.gmail.com"
B. Set your SMTP port number. For gmail you can use "465"
C. Most important part is now. Setting passwords. You have to generate a app password to send email from server. To do so follow the steps from the link. *** Do not use your gmail login password. It will not work. you have to generate app password.If you have enabled 2-step verification then follow the bellow steps to generate app password else just use your gmail password.
https://devanswers.co/create-application-specific-password-gmail/
Step 2: Go to php.ini
A.set the value accordingly for SMTP and smtp_port. Save and don't forget to restart the apache.
从 google 网站查看有关免费 smtp 服务器的信息
https://support.google.com/accounts/answer/ 6010255?hl=zh-CN&visit_id=637965268030667606-3868203439&p=less-secure-apps&rd=1#zippy=%2Cif-less-secure-app-access-is-on-for-your-account
Check this out from the google website with regard to free smtp server
https://support.google.com/accounts/answer/6010255?hl=en&visit_id=637965268030667606-3868203439&p=less-secure-apps&rd=1#zippy=%2Cif-less-secure-app-access-is-on-for-your-account