Environment
- Mautic 7.1.2 (fresh installation)
- AlmaLinux 9.8
- Plesk Obsidian 18.0.77.5
- PHP-FPM
- MariaDB 11.8.8
- Fastmail SMTP
Problem
A fresh installation of Mautic 7.1.2 was successfully configured and connected to Fastmail SMTP. However, every attempt to send a test email resulted in a HTTP 500 error.
The Apache and Mautic logs showed:
PHP Warning: Undefined array key 1 in app/bundles/EmailBundle/Helper/MailHelper.php on line 1789
Symfony\Component\Mime\Exception\RfcComplianceException:
Email "+bounce_xxxxxxxxx@" does not comply with addr-spec of RFC 2822.
Investigation
The problem was traced to the following code in:
app/bundles/EmailBundle/Helper/MailHelper.php
Around line 1789:
if ($settings = $this->isMontoringEnabled('EmailBundle', 'bounces')) {
[$email, $domain] = explode('@', $settings['address']);
$email .= '+bounce';
}
The installation had the following configuration in config/local.php:
'EmailBundle_bounces' => array(
'address' => '',
'host' => '',
'port' => '993',
'encryption' => '/ssl',
'user' => '',
'password' => '',
'override_settings' => '0',
'folder' => ''
)
Because the address field was blank, the call to:
explode('@', $settings['address']);
returned only a single array element, resulting in an undefined domain value.
Mautic then attempted to generate an address such as:
+bounce_6a2919c933580329878193@
which Symfony correctly rejected as an invalid RFC 2822 email address.
Temporary Fix
The following modification was made:
$settings = $this->isMontoringEnabled('EmailBundle', 'bounces');
if (!empty($settings['address']) && str_contains($settings['address'], '@')) {
[$email, $domain] = explode('@', $settings['address']);
}
After clearing the cache and restarting PHP-FPM, email sending worked correctly.
Question
Is this a known issue in Mautic 7.1.2?
It appears that when bounce monitoring settings exist but the monitored address is blank, Mautic still attempts to generate a bounce address and ultimately throws a fatal exception.
Should Mautic be validating that the monitored bounce address is populated and contains a valid email address before attempting to generate the bounce address?
Hopefully this helps anyone else encountering unexplained HTTP 500 errors when testing email delivery on a fresh installation.