Mautic 5.0.0 - Send Email To Contact API 500 error

Your software
My Mautic version is: v5.0.0
My PHP version is: 8.1.18
My Database type and version is: 10.6.15-MariaDB-cll-lve

Your problem
/emails//contact//send throws a 500 error

These errors are showing in the log:

mautic.CRITICAL: Uncaught PHP Exception TypeError: "Symfony\Component\Mime\Address::__construct(): Argument #1 ($address) must be of type string, null given, called in /home/root/domains/domain.com/public_html/app/bundles/EmailBundle/Helper/MailHelper.php on line 929" at /home/root/domains/domain.com/public_html/vendor/symfony/mime/Address.php line 42 {"exception":"[object] (TypeError(code: 0): Symfony\\Component\\Mime\\Address::__construct(): Argument #1 ($address) must be of type string, null given, called in /home/root/domains/domain.com/public_html/app/bundles/EmailBundle/Helper/MailHelper.php on line 929 at /home/root/domains/domain.com/public_html/vendor/symfony/mime/Address.php:42)"} {"hostname":"domain.com","pid":2834374}

Steps I have tried to fix the problem:

I added two extra lines in my MailHelper.php file


    public function addTo($address, $name = null)
    {
        $this->checkBatchMaxRecipients();

        try {
            $this->logError('Debugging.....'); //TEST CODE
            $this->logError($address); //TEST CODE
            $this->logError($name); //TEST CODE
            $name = $this->cleanName($name);
            $this->message->addTo(new Address($address, $name ?? ''));
            $this->queuedRecipients[$address] = $name;

            return true;
        } catch (\Exception $e) {
            $this->logError($e, 'to');

            return false;
        }
    }

And my log looks like this

[2024-01-11 03:46:33] mautic.ERROR: [MAIL ERROR] Debugging..... [] {"hostname":"domain.com","pid":2834374}
[2024-01-11 03:46:33] mautic.ERROR: [MAIL ERROR]  [] {"hostname":"domain.com","pid":2834374}
[2024-01-11 03:46:33] mautic.ERROR: [MAIL ERROR]   [] {"hostname":"domain.com","pid":2834374}
[2024-01-11 03:46:33] mautic.CRITICAL: Uncaught PHP Exception TypeError: "Symfony\Component\Mime\Address::__construct(): Argument #1 ($address) must be of type string, null given, called in /home/root/domains/domain.com/public_html/app/bundles/EmailBundle/Helper/MailHelper.php on line 929" at /home/root/domains/domain.com/public_html/vendor/symfony/mime/Address.php line 42 {"exception":"[object] (TypeError(code: 0): Symfony\\Component\\Mime\\Address::__construct(): Argument #1 ($address) must be of type string, null given, called in /home/root/domains/domain.com/public_html/app/bundles/EmailBundle/Helper/MailHelper.php on line 929 at /home/root/domains/domain.com/public_html/vendor/symfony/mime/Address.php:42)"} {"hostname":"domain.com","pid":2834374}

Not sure why this is blank and where is this function being called from.

Have you set up your DSN provider yet?

Yes and I am getting the test email.
I also get the email when I go in to the contact and send the email manually.
Just running into an issue when its via the API.

Nevermind, I double checked and it was the wrong contact ID, it should have been 2 instead of 1.

PBECAK not Mautic

1 Like

LOL glad you got to the bottom of it, happens to the best of us! :rofl:

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.