The author voluntarily contributed this tutorial as a part of Pepipost Write to Contribute program.
There is nothing wrong with Postfix or PHPMailer! It's really not the reason that your emails are landing in spam.
These are one of the top open-source tools for generating and sending emails at scale. You might be thinking that the default email headers which Postfix or PHPMailer adds might be the reason for emails being landing in spam, but that's not the reason. There are other factors which trigger anti-spam engines to classify your emails as spam. ISPs and anti-spams are worried about three W's:
Who is sending?
What is being sent?
Whom it is being sent to?
Here are a couple of email-related configurations, which will help you to check, how closely your emails compile with various ISP and anti-spam policies:
Sender reputation refers to both the reputation of your sender domain and the IP address (of your server) which is been used to send your emails. Read more on how to check your sender reputation.
If you have set up Postfix for sending just bulk marketing emails and that too to a third party list of non-optin users, then your emails are bound to land in spam in the first go itself. But, if you are sending to an optin user base, then ideally it should not.
But, despite whether your email list consists of optin or non optin userbase, if your emails are landing in spam then throughput/speed of sending emails should be checked. You should not be sending too much in an hour or a day to any ISPs specially to the top ones like Gmail, Yahoo, Outlook.
Here is why?
Because you have not sent anything before to Gmail using this IP address, then for Gmail its like a new IP with neutral reputation. Now, how come this IP started sending so many emails on Day 1 of its sending, when there is no prior history of this IP being used as a mail server.
So, instead of sending too much on Day 1, sending gradually say 100 emails on Day1 and then 150, 200, 500, 1000 and so on. But, remember recipients of your email should open your emails and not report it as spam. Spam Complaints should not be above 0.01% of the number of emails which you sent.
If you follow such a strict warmup process with great user engagement, then this is where you will start building the reputation for you sending IP address.
Many a time, you might have also observed that your first test email with no real content, but just a few test lines also landed into spam. This has mostly to do with your sender reputation and authentication protocols which you are following and not the content.
As discussed above, while controlling the speed of sending emails is important, but at the same time, it is very important to keep a watch on the number of positive engagements (Email Opens, Clicks, Replies and not Spam Complaints/Delete) which you are attracting on your emails.
You can attract positive engagement on your emails only if you are sending which is really an interest for the recipient. If you are using a new IP address then it is always recommended to start with sending good important emails like Signup Confirmation, Order Confirmation, Forgot Password, Notifications and Digest type of emails and not really the marketing emails.
Reverse DNS and PTR records are really a tricky term and not very popularly being used among developers. But, these two play a very important role when it comes to email delivery. Not having these, can make your emails land in spam. You already know about DNS, which maps a domain name to an IP address- This process is actually known as "Forward DNS".
"Reverse DNS" is just the opposite of it, where DNS maps an IP address to a domain name. Both of these are DNS mapping just different in terms of how the lookups happen.Let's now try to understand why this is so important to have this in place. Assume you have a server setup on AWS and sending emails from example.com and using one of the AWS IP address 188.8.131.52 which resolves to some ec2-compute-1.aws.com.
Now, for Anti-spam engines, this looks like an unauthorized email sending. Where the IP which is being used to send emails doesn't resolve to example.com (who is the real sender). However, it is resolving to some other domain ec2-compute-1.aws.com.
PTR record is the one which helps you achieve what you want from reverse DNS. A PTR (pointer) record maps an IP address to the domain name. You can only create a PTR record if you own a dedicated IP address. If you own an IP address, then your IP address provider might have given you the control panel for configurations:
184.108.40.206.in-addr.arpa. 6230 IN PTR mymailserver.example.com.
Note: if above is the PTR record you have created, then make sure all your emails from Postfix or PHPMailer are going with Sender Envelope or Return-Path domain as mymailserver.example.com. Your From/Sender domain can be example.com or anything else also. But, the Return-Path domain should match with the one you have configured in the PTR record.
Mostly in case of VPS and dedicated servers, you get a dedicated IP address. But, if you are on shared hosting then it won't be possible to do reverse DNS setup by creating the PTR records. Here is a list of documentation on how to setup Reverse DNS which some of the popular DNS providers. Based on your DNS provider visit the below links to read the details:
While all of these are not limited but are the leading reasons for your emails to get delivered in the spam folder. Hope this information helped, stay tuned for more insights on handling spam.
In case you have any questions, please feel free to comment below.