When sending an email, only the store mail address is included in the From header in commerce_store_mail_alter. Why not use a slightly more fancy From header that also includes the store name?

-      $message['from'] = $current_store->getEmail();
+      $message['from'] = $current_store->label() . "<" . $current_store->getEmail() . ">";

This will make email programs display the name of the store as the sender instead of the email address.

Snip

Comments

Neograph734 created an issue. See original summary.

neograph734’s picture

Status: Active » Needs review
StatusFileSize
new671 bytes

Status: Needs review » Needs work

The last submitted patch, 2: 3121168-store_name_in_mail_header.patch, failed testing. View results

neograph734’s picture

Status: Needs work » Needs review
StatusFileSize
new2.37 KB

Updated the tests as well.

Status: Needs review » Needs work

The last submitted patch, 4: 3121168-store_name_in_mail_header-4.patch, failed testing. View results

neograph734’s picture

Status: Needs work » Needs review
StatusFileSize
new2.93 KB
neograph734’s picture

StatusFileSize
new2.93 KB

I think that adding a space between the name and address would make it even better. Test <test@example.com> instead of Test<test@example.com>

longwave’s picture

Status: Needs review » Needs work

This doesn't work for me for the order receipt mail - that sets the From address separately, so the check in commerce_store_mail_alter() skips the change.

neograph734’s picture

Status: Needs work » Needs review
StatusFileSize
new4.29 KB

You are right. I've attached a new patch that also updates the order receipt mail and add note to the maintainers to consider removing the from header there and leave everything to commerce_store_mail_alter() instead.
That however, would be a change in the mail id, and could be considered a backwards compatibility breaking change.

longwave’s picture

The ID isn't the problem - the commerce mail handler prefixes all the IDs with "commerce_" already - it's just that "from" is already set.

neograph734’s picture

StatusFileSize
new4.91 KB

That was some thoughtless copy-pasting. This one looks better.

neograph734’s picture

The ID isn't the problem - the commerce mail handler prefixes all the IDs with "commerce_" already - it's just that "from" is already set.

Ah thanks, I was not aware of that. Yet I think the note is still partially relevant as the whole order receipt mail handler should be able to work without the From as well. Why not delegate that to commerce_store_mail_alter()?

Status: Needs review » Needs work

The last submitted patch, 11: 3121168-store_name_in_mail_header-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

neograph734’s picture

Title: Also include the store name in the email From header » Include the store name in the email From header
Status: Needs work » Needs review
StatusFileSize
new6.39 KB

Last attempt and otherwise I will have a look again after the weekend.

This patch removes the defined From header from OrderReceiptMail. It was no different from the default behavior, but was unnecessarily defining it in a second place. This keeps all processing in one place. Also great that there is no BC issue.

longwave’s picture

Yeah, I think removing the "from" from OrderReceiptMail is the way to go.

However commerce_store_mail_alter() assumes the "current store" is the correct one, and that might not be the case, where e.g. an admin is resending an order receipt - it would be better if commerce_store_mail_alter() checked $params for an order and used the store relating to that order, falling back to the current store otherwise.

neograph734’s picture

and that might not be the case, where e.g. an admin is resending an order receipt

Well I did not think of that before, but I bet that is the very reason why it was explicitly set...

it would be better if commerce_store_mail_alter() checked $params for an order and used the store relating to that order, falling back to the current store otherwise.

Would it? For stock commerce maybe, but the commerce infrastructure is bigger and I can imagine (did not check) the same mail handler being used by commerce_wishlist or commerce_invoice as well. In such cases you will not have an order but instead a wishlist or invoice. That would flaw the logic. Instead, the store could be provided to the mail handler. But that would make commerce_store_mail_alter() rather useless.

neograph734’s picture

StatusFileSize
new7.1 KB
new8.26 KB

I've reverted the removal of 'from' from #14. I believe this to be the safest version for now until there is a better alternative.

The alternative version of the patch adds a method to the Store entity to generate the 'from' header in a centralized place.

lisastreeter’s picture

Should the subject be translatable?

Current patch uses sprintf:
+ 'from' => sprintf('%s <%s>', $order->getStore()->getName(), $order->getStore()->getEmail()),

Issue #2924159 Provide a way to customize the order receipt email subject has a patch that includes update to the From header:

+      'from' => $this->t('@storename <@email>', [
+        '@storename' => $order->getStore()->getName(),
+        '@email' => $order->getStore()->getEmail(),
+      ]),
neograph734’s picture

That should not make a difference right? The t() function does not translate placeholders, so the effect is the same?

lisastreeter’s picture

@Neograph734 Re #19

Good point! Thanks, wasn't thinking of how t() works. Comment #18 can be ignored :)

neograph734’s picture

Thanks for the confirmation Lisa :).
Have you (or any of the other people subscribed to this thread) tested the patch? Would be great if somebody could RTBC this so we can get it into a release.

lisastreeter’s picture

Status: Needs review » Reviewed & tested by the community

I was waiting until I had this in production to comment. I can confirm that patch #17 is working properly.

  • jsacksick committed 80c2662 on 8.x-2.x
    Issue #3121168 by Neograph734, longwave, lisastreeter: Include the store...

  • jsacksick committed 7ce700d on 3.0.x
    Issue #3121168 by Neograph734, longwave, lisastreeter: Include the store...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

I went with the extra method, so we don't have to repeat the same logic in multiple places, thanks everyone!

Status: Fixed » Closed (fixed)

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