Wrong charset after update

Created on 23 March 2023, over 1 year ago
Updated 7 December 2023, about 1 year ago

After upgrade to 2.2.x message headers are encoded to "iso-8859-1" by default. Please, return previous behaviour with utf-8 by default. Patch will follow.

🐛 Bug report
Status

Fixed

Version

2.2

Component

Code

Created by

🇷🇺Russia skylord

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

Comments & Activities

  • Issue created by @skylord
  • Status changed to Needs review over 1 year ago
  • Status changed to Fixed over 1 year ago
  • 🇦🇺Australia imclean Tasmania

    Looks good, thanks.

  • 🇦🇺Australia imclean Tasmania

    Actually this isn't the way to do it. The charset can be set in the content-type header.

    What are the steps to replicate this? Versions, sending module (not mail module) etc.

    🐛 Email attachments no longer working Closed: duplicate

  • 🇦🇺Australia imclean Tasmania
  • Status changed to Closed: works as designed over 1 year ago
  • 🇦🇺Australia imclean Tasmania
  • With this fix reversed we have problem that our email has the wrong encoding (using german umlauts).
    Where would this charset be set?

  • Status changed to Postponed: needs info over 1 year ago
  • 🇦🇺Australia imclean Tasmania

    @spruce, can you provide the exact steps to replicate the problem? How are you sending email, where is the wrong charset being shown? Headers (which ones?), body?

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia imclean Tasmania

    It looks like the charset is being set after the other headers have been processed. This patch moves it before the other headers.

    The default is UTF-8, but you can set it in the Content-Type header.

    Does this resolve the issue @skylord and @spruce?

  • Status changed to Closed: works as designed over 1 year ago
  • 🇦🇺Australia imclean Tasmania

    I can't replicate this so I can't tell if the patch in #11 resolves it. If you can provide a set of instructions to demonstrate the the problem then reopen the issue and post it here.

  • Hi,
    It seems the symptom occurs when adding "$message['headers']['Content-Type'] = "text/html";" in hook_mail().

    Steps to reproduce
    1)Upgrade module from 2.1.0 to 2.2.3.
    2)Install module 4.0.2.
    3)Modify /examples/modules/email_example/email_example.module.
    L.53
    case 'contact_message':
    /* add this */ $message['headers']['Content-Type'] = "text/html";
    $from = \Drupal::config('system.site')->get('mail');
    4)Login to your website as administrator, and go to /examples/email-example (or click Examples > Email Example of menu bar).
    Enter your email address in the E-mail address field, enter "あいう" of Japanese in the Message field, and Click Submit button.
    5)Received email shows wrong characters. (See some_characters_wrong.png.)

  • 🇦🇺Australia imclean Tasmania

    @kubokura, you should specify the charset you want in the content-type header.

    $message['headers']['Content-Type'] = "text/plain; charset=UTF-8";
    
  • Thank you for your reply. My comment was not enough.
    - Code of "$message['headers']['Content-Type'] = "text/html";" has worked OK with phpmailer_smtp 2.1.0. I noticed "charset=UTF-8" is added by someone.
    - Code of "$message['headers']['Content-Type'] = "text/html";" doesn't work OK with phpmailer_smtp 2.2.3. I noticed "charset=UTF-8" should be added in the code as you mentioned.

    Today I have confirmed the patch does work for my website, so my information does not help at all. I'm sorry for your confusion.

  • 🇮🇷Iran sgarsivaz

    hi
    I update this module to 2.2.3 and encountered with wrong encodings.
    when I use " Test configuration " every thing are OK.
    but for emails sent by update module, this is what happened :

    New release(s) available for ارزشیابی عملکرد کارکنان

    and this is email header I can see :
    X-Mailer: PHPMailer 6.9.1 (https://github.com/PHPMailer/PHPMailer)
    sender: *************
    MIME-Version: 1.0
    Content-Type: text/plain; charset=iso-8859-1
    Content-Transfer-Encoding: 8Bit

    Steps to reproduce :
    1. drupal 9.5.11
    2. some modules need update (drupal itself needs update to 10.1), set to daily consideration
    3. phpmailer_smtp 2.2.3

    I don't known if it does matter, I also use queue_mail:1.6

  • Status changed to Needs work about 1 year ago
  • Status changed to Postponed: needs info about 1 year ago
  • 🇦🇺Australia imclean Tasmania

    OK I think I understand your situation. Aside from the test and update emails, does your website send out any other notifications?

    What happens when you set the format to HTML in Configuration -> System -> PHPMailer SMTP -> Form (/admin/config/system/phpmailer-smtp/format)

  • Status changed to Needs review about 1 year ago
  • 🇦🇺Australia imclean Tasmania

    @sgarsivaz, try this. It combines #11 and not forcing HTML on plain text only emails. Also try my suggestion in #18.

  • 🇦🇺Australia imclean Tasmania
  • 🇮🇷Iran sgarsivaz

    thanks @imclean
    I used these methods and problem goes away :
    1. setting PHPMailer SMTP -> Format to HTML and it worked
    2. setting PHPMailer SMTP -> Format to PlainText and using patch #20 and it worked

    without these two method, problem remains.
    by the way, for your question, my website send out mails for user registration & update & webform ( by using queue_mail module)

    • imclean committed 765c1870 on 2.2.x
      Issue #3349815 by imclean, sgarsivaz: Wrong charset after update
      
  • Status changed to Fixed about 1 year ago
  • 🇦🇺Australia imclean Tasmania

    Thanks for testing.

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

Production build 0.71.5 2024