HTTP 500 when sending test email if bounce monitoring address is blank
Mautic Series
7.1.x series
Mautic installed version
7.1.2
Way of installing
I downloaded a release from https://www.mautic.org/mautic-releases
PHP version
8
What browsers are you seeing the problem on?
Not relevant
What happened?
This bug was originally reported here: Original report.
Author: McGlinn I am not the original author of the report. I am sharing it here because it may affect other Mautic users and seems worth validating.
Environment
- Mautic: 7.1.2 - fresh installation
- OS: AlmaLinux 9.8
- Server panel: Plesk Obsidian 18.0.77.5
- PHP: PHP-FPM
- Database: MariaDB 11.8.8
- SMTP: Fastmail
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 an HTTP 500 error.
The Apache and Mautic logs showed the following:
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 issue appears to be related to the following code in:
app/bundles/EmailBundle/Helper/MailHelper.phpAround 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, this line:
explode('@', $settings['address']);returns only a single array element. As a result, the domain value is undefined.
Mautic then attempts to generate a bounce address similar to:
+bounce_6a2919c933580329878193@Symfony correctly rejects this as an invalid RFC 2822 email address, which causes the HTTP 500 error.
Temporary workaround
The original reporter tested the following modification:
$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.
Expected behaviour
Mautic should not attempt to generate a bounce address when the bounce monitoring address is blank or invalid.
Before calling:
explode('@', $settings['address']);Mautic should validate that:
- the bounce monitoring address is not empty
- the value contains a valid email address
- the domain part exists before generating the bounce address
Actual behaviour
If bounce monitoring settings exist in config/local.php, but the address field is blank, Mautic still attempts to generate a bounce address.
This results in an invalid address such as:
+bounce_xxxxxxxxx@and triggers a fatal exception when sending a test email.
Question
Is this a known issue in Mautic 7.1.2?
It looks like Mautic treats the bounce monitoring settings as enabled or available because the configuration array exists, even though the actual monitored email address is blank.
Should Mautic validate the monitored bounce address before attempting to generate the bounce address?
This may help other users experiencing unexplained HTTP 500 errors when testing email delivery on fresh Mautic 7.1.2 installations.
How can we reproduce this issue?
Relevant log output
Code of Conduct
- I confirm that I have read and agree to follow this project's Code of Conduct
Care about this issue? Want to get it resolved sooner? If you are a member of Mautic, you can add some funds to the Bounties Project so that the person who completes this task can claim those funds once it is merged by a member of the core team! Read the docs here.
Source: mautic/mautic