phpemaildrupaldrupal-7exim4

Drupal 9 Website Does Not Send Email But Drupal 7 Site Does


Hoping someone can help, this is making me crazy.

For the life of me I cannot get a Drupal 9 site to send PHP Mail, but a Drupal 7 site on basically the same setup does without fail. The only real difference is Drupal 9 is using PHP 8.1.6 and the Drupal 7 site is using PHP 7.3.27.

Web Server for Drupal 9 is Apache/2.4.38 (Debian) Web Server for Drupal 7 is Apache/2.4.25 (Debian)

Both setups are docker php Debian (all the same php-extensions installed on both - nothing different) and Drupal installed with Composer (the recommended way for both)

If I test contact form, password reset and user registration - both sites say they are sending the related emails but only Drupal 7 delivers, Drupal 9 gives no errors in logs and says "sent" just like in Drupal 7 but nothing gets sent.

This is extremely frustrating. Aside from PHP versions they are pretty much identical - why won't Drupal 9 site send PHP emails?

I looked into exim4 (running on both setups live with proper DNS and Records) the logs in exim4 for Drupal 9 originally said Mailing to remote domains not supported - so I looked it up and was told to run configuration wizard and set to Internet/SMTP, so I did (yet the instructions failed to include the 20 extra steps aside from giving the fully qualified domain name which I did) and I honestly have no idea what to set for what - needless to say nothing has worked.

I don't understand why it would work fine without having to change anything for Drupal 7 in regards to exim4 but now I have to change settings in exim4 for Drupal 9 - "That doesn't make any sense whatsoever"

After changing exim4 using config wizard I now get: (in the exim4 mainlog)

xxxx@gmail.com R=dnslookup T=remote_smtp defer (101): Network is unreachable
H=aspmx.l.google.com [2607:f8b0:4004:c08::1a] Network is unreachable
H=aspmx.l.google.com [172.253.63.27] Connection timed out
H=gmail-smtp-in.l.google.com [142.251.16.26] Connection timed out
H=alt1.gmail-smtp-in.l.google.com [2a00:1450:400b:c00::1a] Network is unreachable
H=alt2.aspmx.l.google.com [2a00:1450:400c:c0b::1a] Network is unreachable
H=alt3.aspmx.l.google.com [2a00:1450:4025:401::1b] Network is unreachable

Both sites are domains setup with MX records for use with google workspaces under the same user account (2 different domains) both configured exactly the same, aside from slightly different DKIM and SPF records which are unique to each but validated by Google Workspace as correct.

In regards to exim4 I'm pretty sure I didn't provide some of the correct information needed in the config wizard like user and/or some other stuff I wasn't sure about (probably why the log changed) - yet I didn't have to do any of this with the Drupal 7 site (it just works).

I looked into resetting the exim4 config back to default but there doesn't appear to be a way to do so without running the wizard again, which I'm very unclear on how to do that properly (any directions out there just says select internet option and set the fully qualified domain and that should fix things, completely neglecting the 10 to 15 steps and questions the wizard asks after making those initial choices and providing the domain.

I can't be the only one to have run into this - yet I find nothing out there specific to Drupal 9 - everything is dated like 1 to 6 years old and none of it lines up with this situation.

So...How do I get this working (and is there a clear simple way to reset exim4 to default installed settings without jumping through hoops that make no sense (at least to me)

I don't feel like adding another mail module to Drupal 9 to use a 3rd party SMTP service to send simple contact form emails (but it looks like that will be the only option and shouldn't be) - this should just work out of the box like Drupal 7 and does not.

I'd be happy to provide the Docker files used to build each if that would help (let me know and I'll copy and paste them in a response, I just doubt there will be anything of note that would explain why) - both sites are running on the same server, same firewall, just different containers (they are even on the same internal Docker networks)

I've been beating my head against a brick wall with this for 2 days now, at this point any help would be greatly appreciated!


Solution

  • So to answer part of my own question regarding resetting exim4 to default initial configuration.

    You need to purge it and all configuration files/changes made and then reinstall it.

    To do this

    apt-get purge --auto-remove exim4-config
    

    Using "auto" with purge removes everything including any configurations

    Next just reinstall exim4 (which will set the default configuration as it was initially created/built no-matter how your stack was originally created.

    To do that:

    apt-get install exim4
    

    -and all is back to normal - no need to run the configuration wizard (especially when trying to re-run the configuration wizard to get back to default continually fails to achieve the results your looking for.

    As for the rest I decided to simplify and just setup SMTP authorization module and use an external email (Google Workspaces "formerly G-Suite") to handle all outgoing email for Drupal 9 as NO-ONE can answer the question why Drupal 9 will not send email with PHP like Drupal 7 does out of the box.