Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail function not sending emails to certain addresses

Tags:

html

php

email

I've been using the php mail function to send emails containing account details to clients when they are registered but I have only just found out that some people are not receiving emails. E.g. when I send an email to each of my collegues when testing only me and one other collegue are receiving the email

- me who received email
- [email protected]
- collegue who received email
- [email protected]
- collegue who did not receive emails:
- email 1 - [email protected],
- email 2 - [email protected]
- collegue who did not receive emails:
- [email protected]
- collegue who did not receive emails:
- [email protected]

The emails are not received in the spam folder either..

$from = "companyy <[email protected]>";          
$subject = "$username Account Details for companyy.co.uk";     
$message = "You have been registered as an administrator of companyy Online.
You can manage your clients, bills and other account functions online.       

Your Username: $username
Your Password: $password2
Your Four-Digit PIN: $PIN         

Once logged in you can change your password to something you will find easier to remember. Please delete this email once you have changed your settings or memorised them.           

Thank you        

This is an automated response, please do not reply!";

mail($email, $subject, $message, $from);
Header('Location: results.php?msg=Added Successfully');
like image 392
pam Avatar asked Feb 28 '11 11:02

pam


1 Answers

Here's a dirty little secret about sending emails: you lose control. Once they've left your server, it's by the grace of the internet gods that your email reaches its destination. Along the way it "handshakes" from one network to the next. It reaches its final destination and then is subjected to multitudes of spam filters and rules that many technical people are in the dark on. For instance, did you know that MSN Hotmail, AOL, etc will not accept more than a certain number of emails from a server (ip range) at once? Once you hit the server's predetermined (and unpublished) limit, the email will be held regardless of its spam rating. Eventually it will be let through, but it means that the password request your user does won't be instantaneous. Here's another tidbit--servers gain "trust" based on longevity of the domain and other factors that are also unpublished. Has your domain been live long? Are you listed on a blacklist? Is the email "spammy" (check with a tool like this)

Then there's sites like AOL where even good quality email from good quality servers just doesn't get delivered with regularity. (Google "aol deliverability" for some fun reading)

So, what to do? Start with blacklist checking. If that's good, check the headers. Does the "from" address match the domain the email's being sent from and is that account valid? That can be a big spam red-flag. To avoid this problem, my company (who sends 50,000+ emails per day) usually sets up "dummy" reply-to accounts. Are you in the whitelist for the users you're testing with? Are the users using a program like Outlook which randomly does its own blacklisting? Change your message and see if deliverability improves. Test with multiple different hosts to see if it's just one particular system.

Rinse, repeat, and continue...

like image 161
bpeterson76 Avatar answered Oct 01 '22 11:10

bpeterson76