Can't send mail from localhost/xampp

不羁岁月 提交于 2019-12-22 10:37:38

问题


Failed to connect to mailserver at "mail.google.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

I configured my xampp php.ini and sendmail.ini file to use my Gmail account for sending email from my PHP script. i am using xampp. after changing the [mail function] part of my php.ini looks like this (i have deleted commented outlines for simplicity)

[mail function]
SMTP = mail.google.com
smtp_port = 587
mail.add_x_header = Off

and my sendmail.ini file looks like this

[sendmail]
smtp_server=mail.google.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
auth_username=babar+gmail.com
auth_password=**********

So what have I missed? Why am I getting this error?


回答1:


You are using wrong SMTP settings for gmail. The correct ones are:

In php.ini

[mail function]
;SMTP = localhost
;sendmail_from = me@example.com
sendmail_path = "c:\sendmail\sendmail.exe -t -i"

In sendmail.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
auth_username=me@example.com
auth_password=**********

Remeber: If you have enabled 2 step authentication, you have to create an application specific password.




回答2:


set the smtp_ssl=auto as smtp_ssl=true

because google's smtp server needs ssl



来源:https://stackoverflow.com/questions/17699607/cant-send-mail-from-localhost-xampp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!