Mail from wordpress detected as SPAM (eg on libero.it domain)
This site is made with WordPress, one of the most popular CMS. Convenient, intuitive, certainly not the best product in the universe, but the easiest to manage and develop. Every WordPress site has some features and, among these, there is email sending. For example, an email is sent when a new user registers or if the password is lost. But you can also use the same feature to send emails with the site’s contents, to create a mailing list. This site creates emails with recently published posts or future events and birthdays. For reasons that are quite unknown, however, all emails to @libero.it domains ended up in spam. To solve this problem, I first wrote to the hosting support of this site (which is Aruba), and an intervention was made, on the server side, that I consider useful. I have attached the reply email
[…] I have inserted the DIKIM protocol into the TXT Record. The DKIM protocol requires the sender’s SMTP server to add a signature with a private key in the headers of email messages. This signature can confirm that the email was actually sent by the declared sender and that the content was not tampered with during transport. If the recipient server requires signature verification, a query will be performed on the DNS zone of the sender domain to obtain the configured public key, with which to verify the message that was encrypted with the private key. […]
However, the solution was to add SMTP authentication parameters to the plugin I use to send emails. Aruba, like almost all hosting services, provides credentials to send and download emails, in particular, to download them you refer to the SMTP protocol and by adding the SMTP parameters to the WordPress site the magic happens and emails no longer end up in SPAM! This is the code inserted in the index.php file of the plugin I wrote (to send emails and do other small things).
function custom_phpmailer_init($phpmailer) {
$phpmailer->Host = 'smtps.aruba.it';
$phpmailer->Port = 465;
$phpmailer->Username = <USERNAME_MAIL>;
$phpmailer->Password = <PASSWORD_MAIL>;
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->IsSMTP();
}
function website_email() {
$sender_email = 'contatti@mirobarsa.com';
return $sender_email;
}
add_filter('wp_mail_from', 'website_email');
add_action('phpmailer_init', 'custom_phpmailer_init');
To verify the resolution, I’ve used this service https://www.mail-tester.com/ Which generates a different email address each time and, by sending an email to that address, you receive a score that indicates “how much our email was detected as SPAM”. With the change made, I got a score of 10 out of 10 and therefore the problem was solved. I hope this article will help other people with the same problem and if you find it useful, consider a donation.