-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add encoding to TransportBuilder #24906
add encoding to TransportBuilder #24906
Conversation
Hi @elvinristi. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
@magento give me test instance |
Hi @elvinristi. Thank you for your request. I'm working on Magento instance for you |
Hi @elvinristi, here is your new Magento instance. |
Verified in test instance that when I including non-ASCII chars in Sender Name-fields under Store Email Addresses and trying to subscribe to Newsletter from the footer then message |
Hi @elvinristi, thank you for your contribution! |
…n check similar to Zend\Mail\Header\AbstractAddressList
Hi @VladimirZaets, thank you for the review. |
@elvinristi thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository. |
✔️ QA Passed |
I use latest Magento, 2.3.3, with the email patch EmailMessageInterface_2.3.3_backward_compatibility_module-email.patch
@elvinristi Any idea about how to fix it? |
@elfeffe got the same issue did you find a fix ? |
@grll no, my Magento store is not sending emails when the customs has an accent on his name, this is terrible. |
same here! What to do? Magento ist not usable at the moment |
Any solution? Same issue here |
Hello guys, after all the patches and investigations, I have managed to fix the mailing issue for M2.3.3. I have overriden the class with di.xml to just extend the send() method and removed the customer name from the headers which solved the issue for me. I was not able to find out whether the name is needed or whether it enhances the email in another way. But for me the main reason for it is to get the emails working. Here is the class in case some one wonders what is going on:
The $this->transportBuilder->addTo can take second argument (customer name) which by default is an empty string. I removed it and the mails started working again. |
Hi,
This also sends emails, if a user with diacritics registers to your shop or any other action that sends emails from magento. Every name will be translated from utf-8 to ascii-charset: Jürgen Müller -> Juergen Mueller Hope this helps. |
Hi, use Magento\Framework\Mail\Address;
use Magento\Framework\Mail\MimePart;
use Magento\Framework\Mail\Template\TransportBuilder as MageTransportBuilder;
use Zend\Mail\Header\HeaderWrap;
class TransportBuilder
{
/**
* @param MageTransportBuilder $subject
* @param $address
* @param string $name
* @return array
* @see \Magento\Framework\Mail\Template\TransportBuilder::addTo()
*/
public function beforeAddTo(MageTransportBuilder $subject,$address, $name = '')
{
if (is_array($address)) {
$this->encodeAdressArray($address);
}
return [$address,$this->encodeString($name)];
}
/**
* @param MageTransportBuilder $subject
* @param $address
* @param string $name
* @return array
* @see \Magento\Framework\Mail\Template\TransportBuilder::addCc()
*/
public function beforeAddCc(MageTransportBuilder $subject,$address, $name = '')
{
if (is_array($address)) {
$this->encodeAdressArray($address);
}
return [$address,$this->encodeString($name)];
}
/**
* @param MageTransportBuilder $subject
* @param $email
* @param null $name
* @return array
* @see \Magento\Framework\Mail\Template\TransportBuilder::setReplyTo()
*/
public function beforeSetReplyTo(MageTransportBuilder $subject,$email, $name = null)
{
//\Magento\Framework\Mail\Template\TransportBuilder::setReplyTo
if (is_array($email)) {
$this->encodeAdressArray($email);
}
return [$email,$name !== null ? $this->encodeString($name) : $name];
}
/**
* @param MageTransportBuilder $subject
* @param $address
* @return array
* @see \Magento\Framework\Mail\Template\TransportBuilder::addBcc()
*/
public function beforeAddBcc(MageTransportBuilder $subject,$address)
{
if (is_array($address)) {
$this->encodeAdressArray($address);
}
return [$address];
}
/**
* @param string $input
* @return string
*/
protected function encodeString(string $input)
{
return HeaderWrap::canBeEncoded($input) ? HeaderWrap::mimeEncodeValue($input,MimePart::CHARSET_UTF8) : $input;
}
/**
* @param array $addresses
*/
protected function encodeAdressArray(array $addresses)
{
foreach ($addresses as $address) {
if ($address instanceof Address) {
$name = $this->encodeString($address->getName());
$mail = $address->getEmail();
$address->__construct($mail,$name);
}
}
}
} Hope this helps! |
From what we experienced, it seems this patch solves encoding of utf8 symbols, let's say emails are sent if sender name is "Čšćžđ", but if sender name contains @<> or similar symbols, our server refuses to send email because of "Mail failure - malformed recipient address" I'm not sure if this is a problem in Zend or Magento, but 2.3.3. completely broke email sending for us which is terrible. So, as already mentioned by others, we also tried all official patches (EmailMessageInterface_2.3.3_backward_compatibility.patch + this PR) and it didn't help for 2.3.3. |
Hello, @elvinristi I am also getting same issue with Magento 2.3.3 version. Contact us and order emails not getting send to customer as well admin. We have not added any non-ASCII chars to email sender and/or receiver detail. NOTE: We have migrated data from Magento 1.9 to Magento 2.3 It would be good if you can suggest us what can be the issue into this case. |
would you mind telling me where to put this plugin? |
Issue found by me and it has been solved. The issue was, the template of contact us form was not there in Magento 2 as we have migrated data from Magento 1. Set contact form template to default and all emails are start sending. |
This did not work for us:
That only resulter these two errors to debug.log:
But the following modification did work and order confirmations seem to be sending again even with special characters:
|
Could you elaborate little more on this? So this can be solved in admin interface? Does it only solve issue for contact us email or for all transactional emails? In my case all mails don't work if there is special character in it in Magento 2.3.3. (which is like half surnames in my country) |
@kovinet It solved issues with all emails. |
@Vishrootways by template you mean the one in Marketing > Email Templates? |
No, check under below locations, remove and type email manually for all emails under below locations.
|
I see, TY. But in my case this was not not problem, but applying patch EmailMessageInterface backward compatibility issue patch for Magento 2.3.3 resolved the issue. |
The issue is reproducible on Magento 2.3.4 with customer name, that contains special characters like ö, á etc.
I confirm, that this fixes issue on top of Magento 2.3.4. |
@oleksii-lisovyi When without |
@elvinristi, yes, the issue is actually connected with using of module I suppose, that some people can't recognize the difference between vanilla Magento and using 3rd party module, but the definitely are complained about the real issue causes their websites. |
@oleksii-lisovyi , ok, thanks for the heads up! |
Confirm this plugin fixes this issue in 2.3.3. If you have set mail delivery to async all previously failed emails will deliver after the plugin is activated.
|
Sorry, but I still don't understand how I can fix this issue in 2.3.3. The patch mentioned by @kovinet does not help and I don't have the gmailsmtpapp module installed. |
@euchenhofer this ticket is only one part. Until you haven't applied official patch I think this is included also in M2.3.3-patch1 release. |
@elvinristi the patch is only relevant if you are using third party modules to send email. @euchenhofer the plugin code posted above does fix this problem, I have verified that and it is running in our production store. If you are unable to implement the plugin yourself in a module then perhaps we can create a module for you. |
@gaiterjones if you mean patch |
Description (*)
While having Magento 2.3.3 and when customer registers account while having in name non-ASCII chars then after form submit User doesn't receive email and log file
var/log/exception.log
included Exception with messageInvalid header value detected
More details in #24902
Fixed Issues (if relevant)
#24902 M2.3.3 breaks email sending when name contains non-ASCII char
Manual testing scenarios (*)
õöü
Questions or comments
Contribution checklist (*)