How to avoid emails going to spam when sending with PHP

I have a web application that sends e-mails, but it was ending up in the user’s spam/junk folder.

I was using PHP’s mail() function. I tried adjusting the “headers” that can be sent (one of the optional parameters in the mail() function), but that didn’t help.

I think the problem was that my mail server’s IP was on some sort of blacklist. I asked the host to look into it, and they said the tests came back okay. I asked my host if they could change the IP, but that didn’t work either. I’m pretty sure the cause was the host; as when I later transferred websites to places such as GoDaddy and HostGator I didn’t have this problem.

Anyways, the solution was to send an e-mail through SMTP instead of PHP’s mail(). For this app, I had Google Apps for Domains enabled, so that Gmail was my e-mail host. In code, I supplied the e-mail username/password. The e-mails sent even appear in my “Sent Mail” items.

Update: my current approach is to use 3rd party software to send out e-mails. Lately I’ve been using Amazon SES. In the past, I’ve also had good luck with Send Grid and MailGun. Other big names, that I haven’t tried exhaustively, are PostMarkApp and MadMimi.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store