No Code Attached Yet
avatar TLWebdesign
TLWebdesign
6 Nov 2025

Steps to reproduce the issue

Send an e-mail with the default Mailer instance. Return Path and envelope-from are not aligned with "From" e-mail header. I noticed this when i was using MailTemplate to send e-mails without passing a custom Mailer to the MailTemplate.
It produces headers like this:

Return-Path: <user1@srv1.example.nl>
    (envelope-from <user1@srv1.example.nl>)
From: Example Name <noreply@domain.nl>

But when i do a $mailer->setSender() and then pass that to the MailTemplate, It produces these e-mail headers:

Return-Path: <noreply@domain.nl>
(envelope-from <noreply@domain.nl>)
From: Example Name <noreply@domain.nl>

This improves e-mail deliverability because now these domains are aligned with the SPF and the DKIM records. Where before they were not.

Expected result

E-mail header domains aligned

Actual result

E-mail header domains not aligned.

Additional comments

I think the root cause is this line:

if ($mailer->setFrom($mailfrom, MailHelper::cleanLine($fromname), false) === false) {
where we set the default true (3rd param) to false.

Where as in the Mail class we don't do this:

$result = $this->setFrom(MailHelper::cleanLine($from[0]), MailHelper::cleanLine($from[1]));

avatar TLWebdesign TLWebdesign - open - 6 Nov 2025
avatar joomla-cms-bot joomla-cms-bot - change - 6 Nov 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 Nov 2025
avatar TLWebdesign TLWebdesign - change - 6 Nov 2025
Title
inconsistent envelope from in MailerFactory vs Mail class
[5.4] Inconsistent envelope from in MailerFactory vs Mail class
avatar TLWebdesign TLWebdesign - edited - 6 Nov 2025
avatar TLWebdesign
TLWebdesign - comment - 6 Nov 2025

@laoneo i see you did the MailerFactory.php is there a specific reason why you chose to set the auto param (3rd one) to false? Maybe i'm overlooking something why it is set to false.

avatar laoneo
laoneo - comment - 7 Nov 2025

This code was more or less copied from the j3 factory equivalent. Pretty sure there was no specific reason.

avatar TLWebdesign
TLWebdesign - comment - 7 Nov 2025

Hi, ah ok thanks for letting me know 😄 i'll create a PR for this.

avatar Fedik
Fedik - comment - 7 Nov 2025

Can you please share the code you use. It is not very clear what exactly you doing.

Side note: I doubt we can change the behavior, as it may break many many existing sites.

avatar TLWebdesign
TLWebdesign - comment - 9 Nov 2025

Hi @Fedik,

It is a direct copy form the code from this user -> joomla plugin here:

$mailer = new MailTemplate('plg_user_joomla.mail', $userLocale);

        $mailer = new MailTemplate('plg_user_joomla.mail', $userLocale);
        $mailer->addTemplateData($data);
        $mailer->addUnsafeTags(['username', 'password', 'name', 'email']);
        $mailer->addRecipient($user['email'], $user['name']);

See now the MailTemplate is not being passed a Mailer instance so it relies on the default mailer where the 3rd flag for setSender defaults to "false". Why i don't know, because even in phpMailer itself this flag defaults to true (as it should).

So my suggestion is to also have Joomla default this to true because it benefits e-mail deliverability across the board.

I am curious tho how improving the envelope from would cause existing sites to break?

avatar Fedik
Fedik - comment - 10 Nov 2025

Okay. Yeah, maybe it not that much b/c break as I thought.
You can send a PR and we will discuss further.

avatar richard67 richard67 - close - 10 Nov 2025
avatar richard67
richard67 - comment - 10 Nov 2025

Closing as having a pull request. See #46431 .

avatar richard67 richard67 - change - 10 Nov 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-11-10 12:29:32
Closed_By richard67

Add a Comment

Login with GitHub to post a comment