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('[email protected]', 'the subject', 'the message', 'From: [email protected]', '[email protected]'); ?>
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
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: <[email protected]>' . "\r\n" . 'Reply-To: <[email protected]>'; mail('<[email protected]>', 'the subject', 'the message', $headers, '[email protected]'); ?>
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.
$headers = 'From: <[email protected]>' . "\r\n" . 'Reply-To: <[email protected]>'; mail('<[email protected]>', 'the subject', 'the message', $headers, '[email protected]'); ?>
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
I have found that adding SPF and DKIM records to DNS solved the problem. I can use the phpmail() function to send to a list of Gmail subscribers.
- The domain in the email used in the -f option in the php.ini sendmail parameter or in the mail() extra parameters field, needs to have a valid SPF record for the domain.
- You should also use a domain key or DKIM. The trick here is that the domain key/DKIM is case sensitive!
After updating the records the mails get delivered to Gmail, Yahoo and AOL addresses.
Read the source here. Comments by ABOMB