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');
?>
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.
Try putting <> around the From and Reply to addresses. I had that same problem with work emails.
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.
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