Really scratching my head with this one and hoping that someone can help.

I have built a site which makes use of Drupal's default contact form. Trouble is my client doesn't receive any emails from the contact form. The client operates their email through Office 365.

For testing purposes I have added my gmail address (as well as the client's) to the recipient list. I receive contact form emails in my gmail account but my client does not. I have even asked for my own account at the client's domain on Office 365 and can confirm that Drupal contact form emails just do not arrive. Nor are they sent to the junk email folder.

What is going on?

An email header from a message received by my gmail account is copied below.

-------

EDIT.
I have removed the header information as it was revealing valid email addresses.

Comments

kruser’s picture

Check that the web server is looking at the correct MX record. Since the email is hosted seperatly from the website, the web hosting server won't know that by default and think the email is hosted locally, which is why the email isn't going through.

-----------------------------------------------------
Bob @ Drupal Aid (https://www.drupalaid.com)

ledbelly2142’s picture

Where do you look for the correct MX record, the php.ini? or is there a Drupal configuration where the mx can be specified?

Thanks!

kruser’s picture

-----------------------------------------------------
Bob @ Drupal Aid (https://www.drupalaid.com)

ledbelly2142’s picture

Thanks!

MrPaulDriver’s picture

In my case, this turned out to be rather more complicated than I ever expected and was all to do with SPF records.

I came to learn that SPF records are similar to DNS records and tell a recipient's email service which domains are allowed to deliver email on behalf of the sender. This is to guard against email address spoofing, where a message has apparently been sent by a genuine sender but in fact has originated elsewhere. Moreover, this issue is nothing to do with Drupal and to confuse matters further, email address spoofing has a number of valid applications, as well as also being widely used by spammers.

To enable a quick reply, email from a Drupal contact form appears to be from the individual who completed the form, but actually this is not the case as the email has actually been sent using php mail by your Drupal website at www.yourdomain.com or perhaps via an smtp server such as mail.yourdomain.com. Alternatively it may have been sent through an unrelated IP Address or domain, perhaps that of an external mail server.

If using SMTP an SPF record may be included with the inbound email to verify that it has been sent via approved channels and third party email services such as Gmail and Outlook use this information to help determine whether an inbound message is likely to be genuine or not.

Confusion can arise because some services may not even classify suspect inbound messages as spam and may bounce them before they ever arrive at their destination. In our case, this was the reason why messages were not being found in the client's Outlook spam folder.

In the case of this client's shared hosting, the SPF records were automatically taken care of by the hosting company. Using cPanel we were able to view the records in the Advanced DNS Zone editor. From there we could see that SPF records were fairly strict and allowed email from related MX records plus a specified IP address. Initially, this seemed logical but we came to realise that this rule did not allow for Outlook also being used to send email for this client, quite independently of the clients's website and their hosting account. There had to be something else (perhaps another SPF record somewhere) and it turned out that my client's Outlook service was configured for the highest levels of spam protection by the system administrators at their head office.

To get around this I first tried installing the SMTP module. This is used to send website email via a specified smtp server instead of php mail. I can see how this would be a fitting solution in many cases, but this didn't help with my client's problem.

They are now making use of the Mandrill module to help ensure that messages are being delivered. The Mandrill service provides a number of other methods for authenticating email and once I enabled, contact form emails started immediately coming through to my client but they were being classed as spam. This was actually a big improvement, as it was now possible to configure some email spam rules to filter them out. This wasn't the end of our troubles, but things were getting better.

By the way. There is more to using Mandril than just installing the Drupal module and I advise researching the subject well. This video, although pretty long, proved to be invaluable in helping me to understand the issues.

As mentioned above, I eventually narrowed the problem down to an Enterprise scale installation of Office 365 Outlook which didn't allow for email being sent through other channels, such as a client's website, when it was sharing exactly the same domain. In fairness, it would not be practical for this client's service provider have knowledge of all other channels either.

I had to provide SPF records to acknowledge Outlook's primary role in the sending of this organisation's email whilst also advising it of others. I have since found similar issues for a different client using who is using Google Apps (Gmail). I guess that Outlook believed it owned the canonical MX or SPF record and had to be properly convinced that email was allowed to go via alternative channels.

Summed up; SPF records may need to acknowledge email being sent by third party services such as Outlook or Gmail as well by the website's domain or IP address for any email generated by site.

If there is anything I've missed or if I've got anything wrong, please chip in.

----
The official SPF documentation site is http://www.openspf.org/

The examples given below may not be right for you but should help with the general principles

Allow Server IP Address and Outlook - Office 365 customers (change the IP address for your own website)
v=spf1 +a +mx +ip4:95.142.159.2 include:spf.protection.outlook.com ~all

Allow Mandrill and Gmail - Google Apps customers
v=spf1 include:_spf.google.com include:spf.mandrillapp.com ~all

Allow Outlook, Mandrill and Gmail - For an organisation using both Outlook and Google Apps
v=spf1 include:spf.protection.outlook.com include:spf.mandrillapp.com include:_spf.google.com -all

This last example might sound unlikely, but consider a school using Office 365 for staff email, but Google Apps for Education and Google Classroom for its pupils.

---
Paul Driver
www.easable.uk
Ilkley, West Yorkshire, UK

ledbelly2142’s picture

Paul,
This is a huge help in troubleshooting the issues. Thank you.

-Greg

Jaypan’s picture

To enable a quick reply, email from a Drupal contact form appears to be from the individual who completed the form

Not by default. It must be a module you've enabled on your site. By default, email from Drupal contact forms comes from the site address itself.

beesol’s picture

solved using this tip - Allow Server IP Address and Outlook - Office 365 customers

Thanks Paul

auvietco’s picture

Thank you

Seniorenbond_sente’s picture

Mr Pauldriver,

I run the website seniorensente.be  ( website for local seniors registered) 

For preparing drupal 10  I shwiched to PHP 8.16.

I came after testing that all e-mailadresses whit a dot in the first part of the adress  ( xxxx.yyyy@zzzz.nn )dont receive the mail. except the e-mails to @gmail.com

All logs drupal views_send are identic, logs track_delivery in c-panel are accepted

   Did not receive annie.tack@skynet.be , bart.dc@live.be, jacques_ostyn@hotmail.com
                               annie.tack@skynet.be asking a new password.

     Did received  fernand.devriendt44@gmail.com.

If  i shwitched back to PHP 7.4 all was back normal.

I tell my webhost NEOSTRADA from the problem buth nottingh is moving.

I can't go back now to PHP 7.4 composer give a error and the website do not start.

How can I tackle the problem?

Thanks