Reputation: 42753
I have this code for sending mail
$to = "[email protected]";
$subject = "mail title";
$message = "mail content";
$from_mail = "[email protected]";
$headers = 'MIME-Version: 1.0\r\n'.
'From: '.$from_mail.'' . "\r\n" .
'Reply-To: '.$from_mail.'' . "\r\n" .
'Content-type: text/html; charset=utf-8' . "\r\n";
'X-Mailer: PHP/' . phpversion();
This code sends mails for any mail provider except @gmail
.
What may be reason for this
Upvotes: 0
Views: 1742
Reputation: 26066
My guess—as is others—is that your message went to a SPAM folder. But it is unclear what machine this script is on. Is this your localhost test environment or another isolated development server? Or is it a functioning production server?
If this is a localhost or other isolated test environment, my guess is that Gmail—and possibly even AOL—are blocking your mail as potential SPAM.
But if this is a forward facing production server, the problem can most likely traced to a missing PTR (aka: Reverse DNS record) for the IP address the machine is on.
As explained on this site.
PTR records are mainly used to check if the server name is actually associated with the IP address from where the connection was initiated.
Meaning, many mail servers are setup to simply mark any message as SPAM if they cannot connect a valid PTR record to the domain.
Also, if this is a production server with multiple IP addresses, there might be an issue with your SPF (Sender Policy Framework) record. Read up more on this site:
Even more precisely, SPFv1 allows the owner of a domain to specify their mail sending policy, e.g. which mail servers they use to send mail from their domain.
So an SPF record is a DNS record that basically says: “Okay, you think you are an e-mail from xyz.com
IP address 1.2.3.4
? Let me look up your SPF record, and hey! The SPF record says that any e-mail sent from the IP address of 1.2.3.4
is cool with xyz.com
! You are not SPAM.”
While there are other factors such as delays in delivery or receipt when dealing with e-mails, I am pretty confident resolving the PTR and the SPF status of the IP address you are sending from will clear this up. This is not a coding issue but a networking and mail infrastructure configuration issue on your side.
Upvotes: 3
Reputation: 2452
Because of spam, email providers are getting more and more stringent about accepting mail.
If you are using shared hosting, then probably that email server will have a bad reputation and you may have to change provider or use whatever mail service they provide. emailing support may be a good start
Many times, mail is not completely blocked but delayed. I would wait a while and check if email gets there. I would also check the mail queue and see what the status of the email is
make sure that you have the appropriate DNS records: _ dkim _ spf _ dmarc
Make sure that reverse dns is setup and that the ip is not in a blocked pool,
Also, make sure you are not on any block list.
IP reputations matter and get improved over time.
Upvotes: 2