Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm increasingly finding that hosting providers are tightening up on email policies, including blocking emails coming from sites hosted on their servers where the From: address is not in the same domain as the website. This approach means that Drupal's contact form stops working. A better approach could be to have the contact form send emails with the site's admin address as the From: address, and include the sender's address elsewhere.
Comments
Comment #1
rickfitz CreditAttribution: rickfitz commentedAs of 7.26 (not checked earlier releases), the sender's name and email address are included in the message body, but it still tries to send using the sender's email address, so is rejected by the SMTP server.
A very simple patch to 'contact.pages.inc' seems to fix this, at least for my usage. In each call to 'drupal_mail' simply delete the last parameter. This causes Drupal to use the site's default email address instead.
I guess the ideal fix would be to add a config option to use either the sender's address or the site's address.
Comment #2
CDU CreditAttribution: CDU commentedThis also causes Gmail to reject contact emails because the "From" address is different than the "Sender" address in the email headers.
I know you are not supposed to hack the Drupal core, but I had to, in order to stop Gmail from rejecting these emails, or marking them as spam.
I changed line 152 in the contact.pages.inc file from this:
drupal_mail('contact', 'page_mail', $to, language_default(), $values, $from);
to this:
drupal_mail('contact', 'page_mail', $to, language_default(), $values);
This solved my immediate problem, but it would be nice if this was fixed in future releases of the Drupal core.
I second rickfitz's suggestion that "the ideal fix would be to add a config option to use either the sender's address or the site's address."
Comment #3
erald CreditAttribution: erald commentedYahoo is also rejecting mails with email address [name]@yahoo.com
Getting nuts of Yahoo changing to rules all the time..
this patch helps. to avoid the problem.
Comment #4
dcam CreditAttribution: dcam commentedChanges will have to be made in 8.x first.
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedI have fixed this problem in a Drupal 7 site with hook_mail_alter. See #2219627: Contact Form: sender address uses not the configured sender #3.
Comment #6
larowlanAs there is an existing work-around involving hook_mail_alter, dropping this to minor
Comment #7
andypostAlready fixed in #111702: Set fixed "from:" and add "Reply-to:" to comply with DMARC