Skip to content

Magento 2.2.4 not sending from sales sender #16355

Closed
@versdivers

Description

@versdivers

Preconditions

  1. Magento 2.2.4
  2. PhP 7.1
  3. Apache

Steps to reproduce

  1. Set general store email addresses
  2. Set store specific email senders in Sales Emails
  3. Send order/shipment/creditnota/invoice mail to customer

Expected result

Email is sent from store email address

Actual result

It sends from the mail server default mailadress

Why

In vendor \magento\module-sales\Model\Order\Email\SenderBuilder.php the configureEmailTemplate() function as been changed.

You can see that
$this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity());
has been changed to

        $this->transportBuilderByStore->setFromByStore(
            $this->identityContainer->getEmailIdentity(),
            $this->identityContainer->getStore()->getId()
        );

With further inspection it on first glance it returns the same result .

Eventually the from gets formatted within the _formatAddress function within Zend/Mail.php and used within the same class at setFrom function which has
$this->_storeHeader('From', $this->_formatAddress($email, $name), true);

The 'From' header can have something like Test Mail test@mail.com or just test@mail.com. But the function itself returns just Test Mail with no email.

And that is because the sprintf function appearently seems to have issues with <> signs. Note sure why.

So i changed

            $encodedName = $this->_encodeHeader($name);
            if ($encodedName === $name  &&  strcspn($name, '()<>[]:;@\\,.') != strlen($name)) {
                $format = '"%s" <%s>';
            } else {
                $format = '%s <%s>';
            }
            return sprintf($format, $encodedName, $email);

to

            $encodedName = $this->_encodeHeader($name);
            if ($encodedName === $name  &&  strcspn($name, '()<>[]:;@\\,.') != strlen($name)) {
                $format = '"%1$s" %3$s%2$s%4$s';
            } else {
                $format = '%1$s %3$s%2$s%4$s';
            }
            return sprintf($format, $encodedName, $email , '<' , '>');

and now it does return Test Mail test@mail.com. So that is fixed;

And now i am stuck.

this->transportBuilder->setFrom($this->identityContainer->getEmailIdentity());

-->sends what i need.

      $this->transportBuilderByStore->setFromByStore(
            $this->identityContainer->getEmailIdentity(),
            $this->identityContainer->getStore()->getId()
        );

-->sends from my SMTP servers default emailaddress.

It seems like the headers are reset somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions