PHP mail() function will not send to gmail but will send to my non-gmail account

Go To StackoverFlow.com

7

For some reason the php mail() function is not working properly on a site I am building. I tried to troubleshoot the issue down to its simplest form, and came up with this file:

<?php
mail('myEmail@gmail.com', 'the subject', 'the message', 'From: webmaster@example.com', '-fwebmaster@example.com');
?>

when myEmail is a gmail account, I never recieve the message. However when I use a non-gmail account, I do recieve the message. I am at a loss and have tried everything to figure this out. I am starting to think it is an obscure host/server issue. You can see the server specs here: http://aopmfg.com/php.php

Any ideas?

EDIT - let me also add that this was all working fine a few weeks ago, the last time I tested it. No significant code changes since then at all.

EDIT 2 - After reading a similar post I tried adding From and Reply-To headers... still no luck. New code:

<?
$headers = 'From: <some@email.com>' . "\r\n" .
'Reply-To: <some@email.com>';

mail('<myEmail@gmail.com>', 'the subject', 'the message', $headers,
'-fwebmaster@example.com');
?>
2012-04-05 01:50
by ARH3
BREAKING NEWS: have you checked your spam label under your gmail - Andreas Wong 2012-04-05 01:54
yes I checked my spam : - ARH3 2012-04-05 02:08
Use a Mail Class like SwiftMailer. That helps getting away from this weird mail problems - binarious 2012-04-05 02:15
this problem actually stemmed from a WordPress project I am doing. I am using the plugin ContactForm7, which is a very reputable plugin and one that I use all the time. I tested it on this site when I set it up a few weeks ago and it worked fine. I wanted to see if the issue was related to WordPress, ContactForm7, or something outside of that so I made the code shown in the question and discovered that that does not work either - ARH3 2012-04-05 02:22


8

It turns out that Google blocked my server because another site on the same server was hacked and used for spam.

To test and ensure that it was a problem with the server, I created a simple PHP file that would send an email to my email address on page refresh. It worked when I sent to my exchange-based email address, but not to any Google-related accounts.

Code:

$headers = 'From: <test@test.com>' . "\r\n" .
'Reply-To: <test@test.com>';

mail('<myEmail@gmail.com>', 'the subject', 'the message', $headers,
  '-fwebmaster@example.com');
?>

Thanks for the help all.

2012-04-23 01:22
by ARH3
Thanks. Worked like a charm - emuigai 2016-04-11 21:22


1

Try putting <> around the From and Reply to addresses. I had that same problem with work emails.

2012-04-05 02:03
by Cassie Smith
Just tried this - no luck : - ARH3 2012-04-05 02:11


1

I had a similar problem with gmail. However my subject title was "See if you have won". When I changed this to something less marketing/spammy, it came through. So it's not always the PHP code who is causing this, but it can be the subject title as well which is blacklisted.

2013-11-04 10:03
by Wim


0

I was having the same problem. But when I checked my C:\xampp\mailoutput folder, the mail sent was received in this folder. Now please check and do the needful. It was sent in my testing local server. If it is sent on the real server, that may be on your hosting server and you have to check through site hoster

2017-06-03 14:43
by Dharam Jindal
Ads