Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
Sounds like a network connectivity issue. Perhaps your Internet provider isn't allowing outgoing connections on that port? – Pekka 웃 Jul 17 at 12:21
please tell something more. how to get rid of this problem. – buet_baba Jul 17 at 12:37
add comment (requires an account with 50 reputation)

2 Answers

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

In php.ini

[mail function]
;SMTP = localhost
;sendmail_from = [email protected]
sendmail_path = "c:\sendmail\sendmail.exe -t -i"

In sendmail.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
[email protected]
auth_password=**********

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

share|improve this answer
Let me know if this works for you? – VarunAgw Jul 17 at 12:41
the problem still exists. will u please paste the content of the sendmail.ini file. i m stuck with it. – buet_baba Jul 17 at 18:42
@buet_baba Oops! I given you wrong answer earlier. Now try this. It is tested and working in my PC. – VarunAgw Jul 18 at 11:47
Does this works now? – VarunAgw Jul 19 at 2:17
no, it's not working. can you please send me your php.ini file file and sendmail folder please. i can't get it done. one more thing, which version of xampp do you use? – buet_baba Jul 20 at 10:04
show 5 more commentsadd comment (requires an account with 50 reputation)

set the smtp_ssl=auto as smtp_ssl=true

because google's smtp server needs ssl

share|improve this answer
i have tried this but hasn't worked. the problem is still there. – buet_baba Jul 17 at 12:38
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.