无法通过“mail.google.com”端口 587 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 ini_set()
我将我的 xampp php.ini 和 sendmail.ini 文件配置为使用我的 Gmail 帐户从我的 PHP 脚本发送电子邮件。我正在使用 xampp。更改我的 php.ini 的 [邮件功能] 部分后看起来像这样(为简单起见,我删除了注释大纲)
[mail function]
SMTP = mail.google.com
smtp_port = 587
mail.add_x_header = Off
我的 sendmail.ini 文件看起来像这样
[sendmail]
smtp_server=mail.google.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
auth_username=babar+gmail.com
auth_password=**********
所以我错过了什么?为什么会出现此错误?
最佳答案
您为 gmail 使用了错误的 SMTP 设置。正确的是:
在 php.ini 中
[mail function]
;SMTP = localhost
;sendmail_from = me@example.com
sendmail_path = "c:\sendmail\sendmail.exe -t -i"
在 sendmail.ini 中
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
auth_username=me@example.com
auth_password=**********
记住:如果您启用了 2 step authentication ,您必须创建一个应用程序专用密码。
关于php - 无法从 localhost/xampp 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17699607/