Wrong from address when sending a newsletter

Created on 20 October 2023, about 1 year ago
Updated 16 May 2024, 6 months ago

Problem/Motivation

The configuration entity simplenews have a field where is stored the "from address" when you are sending the newsletters.

That field is storing correctly, but its not used on the class MailManager.php

Steps to reproduce

- Create a newsletter configuration
- Fill the field 'from_address' (and all required fields).
- Create newsletter entity and send it.

It will send the newsletter with 'from_address' from the system site configuration instead of the newsletter configuration.

Proposed resolution

In code, I've just added the right code to take the newsletter configuration instead of system site configuration mail.

In case, we dont have any 'from_address' configured, then it will take the system site configuration.

🐛 Bug report
Status

Postponed

Version

4.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tobas1996
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    61 pass
  • @tobas1996 opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    61 pass
  • @tobas1996 opened merge request.
  • Status changed to Postponed: needs info about 1 year ago
  • 🇬🇧United Kingdom adamps

    $headers['From'] is set in MailEntity::getHeaders()

    I see no need for the extra lines you added. The setting is a from header, it doesn't say it will affect any other headers, often that would be incorrect.

  • Hi!

    I am modifying that function MailEntity::getHeaders() , adding this :

    + $headers['Sender'] = $this->getFromAddress();
    + $headers['Return-Path'] = $this->getFromAddress();

    Maybe you mean that its redundant to pass again to $message['from'] at MailBuilder::buildNewsletterMail().

    If we do not modify this (at least the MailEntity:getHeaders()), the sender is always the configuration system site email.

    Hope it helps

  • Status changed to Closed: works as designed about 1 year ago
  • 🇬🇧United Kingdom adamps

    This is working as designed. If you wish to alter other fields you can write a hook to do it.

  • Status changed to Active about 1 year ago
  • 🇨🇦Canada yang_yi_cn

    We have the same issue. I think if it's "by design" then the design is wrong.

    Bascially whatever "FROM" you set in the Newsletter settings, it doesn't work, It always fallback to site default e-mail.

    I'm not sure about "Return To" part, but from my reading / testing, the $headers['Sender'] is actually needed to get a proper devliery. Just setting "FROM" address will get ignored by most mail servers such as Outlook, Gmail etc. Maybe we should test if it's empty befor settings it?

    $headers['Sender'] = empty($headers['Sender']) ? $this->getFromAddress() : $headers['Sender'];
    
  • Status changed to Postponed about 1 year ago
  • 🇬🇧United Kingdom adamps

    You can set the sender using "Basic site settings" /admin/config/system/site-information

    I'm pretty sure the code isn't going to change in this module. Many others sites are very happy with the way it works now.

  • Yes, we can change the 'Basic site settings' but, maybe we don't want to send the newsletter simplenews emails with that email.

    It should be the email from newsletter, not from the "Basic site settings".

    Hope it helps you!

Production build 0.71.5 2024