Question

Why is PHP's mail function only working for sending to gmail addresses?

I’m trying to set up a PHP document that will send a confirmation email to the user. The email only makes it to the user’s inbox if their email is a gmail account. No other types of emails will work.

Here is what the mail.log file displays for a non-gmail address (I’ve replaced the user emails with “useraddress”, instead of the actual email):

Jun 11 21:25:46 MrGarretto sendmail[13722]: t5C1Pkpi013722: from=www-data, size=417, class=0, nrcpts=1, msgid=<201506120125.t5C1Pkpi013722@mrgarretto.com>, relay=www-data@localhost
Jun 11 21:25:46 MrGarretto sm-mta[13723]: t5C1PkMp013723: from=<www-data@mrgarretto.com>, size=683, class=0, nrcpts=1, msgid=<201506120125.t5C1Pkpi013722@mrgarretto.com>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jun 11 21:25:46 MrGarretto sendmail[13722]: t5C1Pkpi013722: to=(useraddress)@sbcglobal.net, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30417, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t5C1PkMp013723 Message accepted for delivery)
Jun 11 21:25:47 MrGarretto sm-mta[13725]: t5C1PkMp013723: to=<useraddress@sbcglobal.net>, ctladdr=<www-data@mrgarretto.com> (33/33), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120683, relay=al-ip4-mx-vip1.prodigy.net. [144.160.235.143], dsn=5.0.0, stat=Service unavailable
Jun 11 21:25:47 MrGarretto sm-mta[13725]: t5C1PkMp013723: t5C1PlMp013725: DSN: Service unavailable
Jun 11 21:25:47 MrGarretto sm-mta[13725]: t5C1PlMp013725: to=<www-data@mrgarretto.com>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

Here is what the mail.log file displays when the user has specified a gmail address:

Jun 11 21:23:01 MrGarretto sendmail[13701]: t5C1N1dn013701: from=www-data, size=413, class=0, nrcpts=1, msgid=<201506120123.t5C1N1dn013701@mrgarretto.com>, relay=www-data@localhost
Jun 11 21:23:01 MrGarretto sm-mta[13702]: t5C1N1nw013702: from=<www-data@mrgarretto.com>, size=679, class=0, nrcpts=1, msgid=<201506120123.t5C1N1dn013701@mrgarretto.com>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jun 11 21:23:01 MrGarretto sendmail[13701]: t5C1N1dn013701: to=(useraddress)@gmail.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30413, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (t5C1N1nw013702 Message accepted for delivery)
Jun 11 21:25:02 MrGarretto sm-mta[13704]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Jun 11 21:25:03 MrGarretto sm-mta[13704]: t5C1N1nw013702: to=<(useraddress)@gmail.com>, ctladdr=<www-data@mrgarretto.com> (33/33), delay=00:02:02, xdelay=00:02:02, mailer=esmtp, pri=120679, relay=gmail-smtp-in.l.google.com. [74.125.143.27], dsn=2.0.0, stat=Sent (OK 1434072303 ku8si2066020lac.87 - gsmtp)

Also, the PHP file which is sending the emails is on a subdomain of “mrgarretto.com”, if it makes a difference.

This is what my etc/hosts file looks like:

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
127.0.1.1 MrGarretto MrGarretto
127.0.0.1 localhost
45.55.236.86 mrgarretto.com localhost
45.55.236.86 cmd.mrgarretto.com localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Sure! Here is the PHP code that I run to send an email:

$message = "The body of the message";
$message = wordwrap($message, 70, "\r\n");
$headers = 'From: register@mrgarretto.com' . "\r\n" .
'Reply-To: register@mrgarretto.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mailResult = mail($email_a, 'Insert a subject here', $message, $headers);

Hope it helps :)

Hi,

Could you provide your headers configurations? I have the same problem.

Thank you.

I’ve solved it: I simply forgot to include the headers when it sends the mail