Problem/Motivation

This is the Drupal 7 backport of #209672: Use site name in From: header for system e-mails.

The aim of this issue is to give e-mails from the site administrator a "from" title set to the website name and not just an e-mail address.

In Drupal 5 this was possible by configuring "Site Webmaster" <webmaster@site.com> in Site information, but since 6.x the additional validation prevents such an e-mail address configuration.

You are now limited to just the e-mail address, without a name. Hence site e-mails appear to be from just webmaster@site.com, which is just not as nice :)

Proposed resolution

Specify in the "From:" header the site name along with the site email address.

Remaining tasks

User interface changes

In your email, you'll see the Site name instead of the email address.

Screen capture attached of my email client:
Screen capture of emails before and after

API changes

None.

CommentFileSizeAuthor
#32 3098058-32.patch8.43 KBmcdruid
#32 interdiff-3098058-31-32.txt1.16 KBmcdruid
#31 3098058-31.patch8.18 KBmcdruid
#31 interdiff-3098058-23-31.txt3.26 KBmcdruid
#29 3098058-29.patch8.17 KBmcdruid
#29 interdiff-3098058-23-29.txt1.92 KBmcdruid
#28 3098058-28.patch8.17 KBmcdruid
#28 interdiff-3098058-23-28.txt1.92 KBmcdruid
#25 after.png2 KBalexandra.vecher
#25 before.png1.24 KBalexandra.vecher
#23 interdiff_18_23.txt2.55 KBSAVEL
#23 d7-site-name-in-emails-3098058-23.patch7.2 KBSAVEL
#20 gmail2.png73.3 KBSAVEL
#20 gmail.png71.41 KBSAVEL
#20 yopmail.png52.7 KBSAVEL
#19 Email_check_review_result.jpg653.87 KBnikolas.tatianenko
#18 interdiff_12_18.txt5.56 KBSAVEL
#18 d7-site-name-in-emails-3098058-18.patch6.72 KBSAVEL
#12 d7-site-name-in-emails-209672-128-tests+fix.patch2.24 KBalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott credited RobLoach.

alexpott credited carlos8f.

alexpott credited catch.

alexpott credited gdud.

alexpott credited naxoc.

alexpott credited theborg.

alexpott’s picture

Status: Active » Needs review
FileSize
2.24 KB

Here's the patch from @naxoc. Crediting all the contributors from that issue because I think they all worked on the D7 patch too.

apaderno’s picture

Title: Use site name in From: header for system e-mails » [D7] Use site name in From: header for system e-mails
sjerdo’s picture

Status: Needs review » Needs work

If we're considering backporting this to D7, we should also directly backport #2936032: Sites named with special characters cannot send mail. Otherwise we'll be introducing possible bugs for some websites (which we don't want since D7 should be stable).
We should check whether similar bugs of this patch were reported and backport the fixes.

sjerdo’s picture

alexpott’s picture

@sjerdo great catch. I think we should combine the issues for D7.

SAVEL’s picture

Assigned: Unassigned » SAVEL

I'm working on backporting #2936032: Sites named with special characters cannot send mail.

SAVEL’s picture

Assigned: SAVEL » Unassigned
Status: Needs work » Needs review
FileSize
6.72 KB
5.56 KB

I've backported #2936032: Sites named with special characters cannot send mail.
Please, review.

nikolas.tatianenko’s picture

FileSize
653.87 KB

Reviewed.
"Sites named with special characters cannot send mail" - solved
Observation:
I assume that email should be replaced by site name.
Is the current behaviour expected?

SAVEL’s picture

FileSize
52.7 KB
71.41 KB
73.3 KB

Nikolas, it seems like it's Gmail's special behavior with long (or weird) from texts.

I've tried to change a site's name to a shorter one: 'diymus, LTd (x-fac)' and now it's showing at GMAIL UI.

I've also tried to send an email to yopmail with a longer name "Mycompanyname ()<>[]:;@\\,.\"" and it was ok.

Screenshots are attached.

nikolas.tatianenko’s picture

Status: Needs review » Reviewed & tested by the community

Ok.
Let's summarize:
* Site name used instead of email: Done
* Site name encapsulate special characters: Done

Great work!

mcdruid’s picture

Thanks for working on this.

How do we address the concerns expressed by @David_Rothstein / @xjm in the parent issue, but specifically about introducing this to D7 now:

we'd basically be changing it for every Drupal 7 site (at least ones that don't specifically override it) in the middle of a stable release, and I think some sites might be quite happy with just the email address being used here.

This might be an unexpected change for some sites that'd break things like e-mail filters / forwarding set-ups that might have been in place for years.

SAVEL’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +epam-contrib
FileSize
7.2 KB
2.55 KB

Nice catch, @mcdruid!

I've modified the patch so that default behavior isn't changed.
Now to enable showing a site name in "From" header one needs to set 'site_mail_display_sitename' variable to true.
For example, by executing:

variable_set('site_mail_display_sitename', TRUE); 

or changing settings.php

I've also added tests that cover both cases.

Please, review

apaderno’s picture

The patch does what expected, and it adds tests. To me, this is RTBC.

alexandra.vecher’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.24 KB
2 KB

Tested. The results in attached files

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: d7-site-name-in-emails-3098058-23.patch, failed testing. View results

mcdruid’s picture

Issue tags: +Drupal 7 bugfix target

Looks like this was an unrelated testbot snafu; a retest came back green.

I'd like to get this in (we could just about squeeze it into the next release due 2012-12-02 so in one week).

However, I have one or two fairly small tweaks I'd like to suggest:

1) The new drupal_format_mail_name() function is a fairly straight backport of formatDisplayName(). Let's also make the function name match more closely (e.g. drupal_mail_format_display_name() even though that's getting fairly long).

2) Thank you for adding the variable in #23 - however, let's add an entry to default.settings.php for this which explains what it does, and sets it to TRUE for new sites (although we could ask whether those are actually "a thing" for D7 ;).

I think maybe the variable should be called mail_display_name_site_name although I'm not sure there's a "right answer" for that.

It would also be good to add a Change Record / Notice for this pointing out that existing sites might want to enable this feature by setting the variable e.g. in settings.php

Leaving at "Needs work" for those changes.

I'll also add this to #3179845: [meta] Priorities for 2020-12-02 bugfix release of Drupal 7.76 / 7.77 though as I think we can get it into the next release if we work quickly.

mcdruid’s picture

Status: Needs work » Needs review
FileSize
1.92 KB
8.17 KB

Implemented suggestions from #27

mcdruid’s picture

Oops. This time without the typo.

Status: Needs review » Needs work

The last submitted patch, 29: 3098058-29.patch, failed testing. View results

mcdruid’s picture

mcdruid’s picture

mcdruid’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

Fabianx’s picture

RTBM, +1 from me for merge

I like that it is opt-in and that new sites opt-in automatically.

Should add some release notes and a CR so people know that they can easily enable it now.

  • mcdruid committed 6cc9596 on 7.x
    Issue #3098058 by mcdruid, SAVEL, alexpott, alexandra.vecher, nikolas....
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Drupal 7 bugfix target

Thank you everybody!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.