How can I get my DKIM identified?

I’m struggling to prevent my emails from vanishing or ending up in the email spam folder, and it looks like it is my DKIM record that is not identified correctly, so is there anyone who knows how to set up the DNS records correctly for this?

I followed this tutorial

I’m using an Ubuntu 16.04 droplet with WordPress and Postfix, and all email is hosted at Office 365, except a few emails which are posted via a web form on the website, and that’s where this issue comes into the picture.

This is my authentication report:

Summary of Results
SPF check:          softfail
DomainKeys check:   neutral
DKIM check:         neutral
SpamAssassin check: ham

This is my SPF record:

v=spf1 +a +ip4: ~all

This is my DKIM record:


In my mail tester feedback I got the following result:

[SPF] Your server is authorized to use
[Sender ID] Your server is authorized to use
Your message is not signed with DKIM
You do not have a DMARC record
Your server is successfully associated with

Please note that it’s only emails from a web form on the website that ends up in a spam folder, and all emails sent via the website uses Postfix and a PHP mail() function.

I’m not sure I can set a MX record, because last time I tried the Office 365 stop working, so any other advice on how to correct this is appreciated.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I’ve just installed and tried the plugin, but it was never used for sending the email, and I’m not sure what change to make, for it to work either.

I however, noticed that the password for this SMTP service in this plugin was written in clear and readable text in the database, so I’m not sure if this plugin is that secure to install :)

Well, I’ll dig a bit more…


It can be a bit of a headache, though thankfully there are solutions that allow you to work around the need to have and manage your own mail server.

The libraries I linked to are standard PHP libraries, so they don’t need to be physically installed. If you already have PHP working on your Droplet, you’d need to ensure that you’re using an autoloader to handle loading the class files when they are called – either your own, or use Composer.

That being said, since you’re using WordPress, you do have a slightly better option, and that would be to use a plugin. The one I’d recommend installing and using would be WP Mail SMTP:

When configuring the plugin, choose SMTP (not PHP’s mail()) function and then provide your SMTP details. As long as your Office 365 plan allows you to connect from an external server using your login details, you would simply provide those details to the plugin.

If Office 365 does not work, then you would need to sign up for one of the services I mentioned. For the purpose of this plugin, I’d probably go with SendGrid.

Thanks for a great answer - it’s a real headache.

I’m not familiar with anything mentioned above, but the PHPMailer or Swiftmailer looks promising, so do you happens know if there’s any tutorial on how to install any of those libraries on my DigitalOcean droplet?

Is there a requirement to signup for a third-party service to make this work, or can I simply use predefined Office 365 email with credentials to send all emails, or how will it work with my Office 365 hosting?

I tried to follow this tutorial, but that failed miserable, so will above setup be similar?



When it comes to PHP, the mail() function relies on sendmail (handled by Postfix), though setting up proper validation for SPF, DKIM, and DMARC is a little more in-depth to the point where you would be managing your own mail server. The issue there is that, as noted in your OP, you’re using Office 365 and setting up your own mail server and MX would require replacing your Office 365 MX with that of your mail server; they both can’t easily co-exist.

When it comes to setting up a working mail server, you need a valid PTR (Reverse DNS) record, which is easily handled as DigitalOcean takes care of that for you so long as you name your Droplet exactly the same as your hostname.

By the above, I mean that your Droplet name should be a fully qualified hostname, i.e:

and then you need to set your hostname to match (from the CLI):


Once the above is set, you can check your PTR records by logging in to the DigitalOcean CP, visiting the Networking section (link in the header navigation), and then clicking on PTR Records. You’ll see a IP next to each Droplet name.

Once that’s done, you’re shouldn’t have to worry about your PTR, but it’s worth noting as without valid PTR records, you’re mail will most likely still land in the spam box even after you’ve setup SPF, DKIM, and DMARC.

That being said, once you’ve got a valid PTR Record, you’ll now need to configure Postfix and install all bits and pieces required to get SPF, DKIM, and DMARC working. But, if you’re not going to use the Droplet as a fully functional mail server, it’s honestly not worth the hassle or investment.

What I would recommend is instead using a service such as Mailgun or SendGrid and using their API to send mail. This relieves you of having to worry about server-side configurations, IP blacklists, etc.

You can use PHP libraries such as phpMailer or SwiftMailer to integrate with the above services pretty easily, and these services will definitely make life easier (i.e. more time programming, less time worrying about proper setup, security, and other aspects of running a mail server).

Mail Services

PHP Mail Libraries

How To Setup DKIM, DMARC, and SPF