A few words of thanks would be greatly appreciated.

Use Gmail SMTP server

Use Gmail SMTP server


I tried sending emails with the mail () function in php.ini like this:

[Mail function]
; For Win32 only.
; http://php.net/smtp
SMTP smtp.topnet.tn = / * (this is the address of my ISP's SMTP server)
; http://php.net/smtp-port
smtp_port = 25

but mail () function generates the following error: Warning: mail () [function.mail]: SMTP server response: 451
means that: 451 - The command has-been aborted due to a server error.
so I would like to know how to use gmail smtp server if possible.


My message was very clear, I tried with the smtp of my ISP (topnet) but it did not work because it seems to me that the mail () function does not work for
this server (SMTP server response: 451), so I wanted to know what it is possible to use the SMTP server for gmail, and I just found out now that it's possible but after some configuration, this is the Solution:
  • Download msmtp: http://msmtp.sourceforge.net/download.html
  • Install msmtp: I chose to resume the installation of Apache to install msmtp. So I extract the binary archive msmtp.exe previously downloaded and put it in C: \ AMP \ apache \ bin \
  • Configure msmtp: I created a file C: \ AMP \ apache \ conf \ msmtp.conf this way:

tls it
tls_starttls it
tls_trust_file C: \ AMP \ apache \ conf \ ca-roots.crt

default account
host smtp.gmail.com
port 587
auth is
user monCompteGmail@gmail.com
password leMotDePasseCorrespondant
from monCompteGmail@gmail.com
logfile C: \ AMP \ apache \ logs \ msmtp.log

tls_trust_file is required to validate the SSL connection required by Gmail. Geotrust download the file "Equifax Secure Certificate Authority (Base-64 encoded X.509)" I've moved / renamed C: \ AMP \ apache \ conf \ ca-roots.crt.
  • Reconfigure PHP by editing the php.ini file. Comment lines SMTP and sendmail_from then add:

sendmail_path = "C: \ AMP \ apache \ bin \ msmtp.exe - file C: \ AMP \ apache \ conf \ msmtp.conf-t"
  • Restart Apache if PHP is running as a module and you do your testing in this SAPI
  • Test


Solved by azerty123

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled "Use Gmail SMTP server ," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).