We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18878
    • 210 Posts
    Hello,

    Under Tools=>Configuration, on the "User" tab, there are mail format sections for signup, web signup, and web reminder. If I translate this sections using special characters (spanish) the emails arrive with the special characters all corrupted.

    How can I make the special characters look good on emails?

    Thanks.

    Mc
      • 21496
      • 225 Posts
      The problem is that the mails are sent without content type. In order to fix that, you need to modify this file: manager/processors/save_user.processor.php

      What needs to be tweaked is the function sendMailMessage (from Line 445) in that file.

      We need to create the proper headers.

      Sending correct headers also reduces the chances those mails get stuck in a spam filter.

      The code for the function then looks like this:

      // Send an email to the user
      function sendMailMessage($email, $uid, $pwd, $ufn) {
      	global $signupemail_message;
      	global $emailsubject, $emailsender;
      	global $site_name, $site_start, $site_url;
      	$manager_url = $site_url . "manager/";
      	$message = sprintf($signupemail_message, $uid, $pwd); // use old method
      	// replace placeholders
      	$message = str_replace("[+uid+]", $uid, $message);
      	$message = str_replace("[+pwd+]", $pwd, $message);
      	$message = str_replace("[+ufn+]", $ufn, $message);
      	$message = str_replace("[+sname+]", $site_name, $message);
      	$message = str_replace("[+saddr+]", $emailsender, $message);
      	$message = str_replace("[+semail+]", $emailsender, $message);
      	$message = str_replace("[+surl+]", $manager_url, $message);
      	
      	// create proper headers so non-ascii characters are displayed properly
      	$headers="From: ".$emailsender."\n"
      	    . "Content-Type: text/plain; charset=utf-8; format=flowed\n"
      	    . "MIME-Version: 1.0\n"
      	    . "Content-Transfer-Encoding: 8bit\n"
                  . "X-Priority: 3\n"
      	    . "X-Mailer: Content Manager - PHP " .phpversion() . "\n";
      
      	if (ini_get('safe_mode') == FALSE) {
      		if (!mail($email, $emailsubject, $message, $headers, "-f $emailsender")) {
      			webAlert("Error while sending mail to $mailto");
      			exit;
      		}
      	} elseif (!mail($email, $emailsubject, $message, $headers )) {
      		webAlert("Error while sending mail to $email");
      		exit;
      	}
      }
      


      I think the utf-8 charset and complete headers should be used by default for messages sent from the manager, to avoid problems for those using other languages than English, and for not getting trapped in spam filters.
        René
        • 21496
        • 225 Posts
        I found a solution that takes care of the charset as defined in the configuration and makes use of the existing php mailer class, so there is no need to define any headers here. I posted it in this thread, as I think it should be implemented by default.

        I would appreciate some feedback if it works for international users.
          René
          • 18878
          • 210 Posts
          Quote from: nightsignals at Nov 09, 2007, 03:05 PM

          I found a solution that takes care of the charset as defined in the configuration and makes use of the existing php mailer class, so there is no need to define any headers here. I posted it in this thread, as I think it should be implemented by default.

          I would appreciate some feedback if it works for international users.

          Hi,

          I replaced your new code and then under Tools=>Configuration=>User I changed some text at the section Web Reminder Email. I included some international characters like: ignórelo. Then I tested it and clicked on the Lost Password option on the webiste. The email with new password activation arrived, but the international characters are still garbled: ignórelo.

          Did I forget to tweak something else? (My character encoding is Unicode (UTF-8) - utf-8 )

          Thanks.

          Mc
            • 21496
            • 225 Posts
            ah I see you posted here and in the other thread in the wishlist. Let’s keep the discussion here.

            Can you please post the headers of the mail you received?
              René
              • 18878
              • 210 Posts
              Quote from: nightsignals at Nov 16, 2007, 10:08 AM

              ah I see you posted here and in the other thread in the wishlist. Let’s keep the discussion here.

              Can you please post the headers of the mail you received?

              Rene,

              Here are the headers:

              Return-path: <[email protected]>
              Envelope-to: [email protected]
              Delivery-date: Fri, 16 Nov 2007 09:35:52 -0600
              Received: from myusername by myEmailServer.com with local (Exim 4.66)
              (envelope-from <[email protected]>)
              id 1It3EW-0001bI-O9
              for [email protected]; Fri, 16 Nov 2007 09:35:52 -0600
              To: [email protected]
              Subject: Activación de Nuevo Password para Su Empresa
              From: [email protected]
              X-Mailer: MODx Content Manager - PHP/4.4.4
              Message-Id: <[email protected]>
              Date: Fri, 16 Nov 2007 09:35:52 -0600



              Thanks.

              Mc
                • 21496
                • 225 Posts
                The line "X-Mailer: MODx Content Manager - PHP/4.4.4" in your headers is indicating that you’re not using PHPMailer class.

                The international characters are not showing correctly because the mail is still sent without the correct Content Type utf-8.

                Using the PHPMailer class for sending mails would output these headers:

                X-Mailer: PHPMailer [version 1.73]
                MIME-Version: 1.0
                Content-Transfer-Encoding: 8bit
                Content-Type: text/plain; charset="UTF-8"
                


                I assume you did not implement the function sendMailMessage correctly in save_user.processor.php, as described here: http://modxcms.com/forums/index.php/topic,19669.0.html

                I’m posting here the complete modified file. Rename the existing save_user.processor.php in the /manager/processors/ directory of your modx installation. Then change the extension from the attached file from txt to php and upload it to your server.


                  René
                  • 18878
                  • 210 Posts
                  Quote from: nightsignals at Nov 19, 2007, 11:55 AM

                  The line "X-Mailer: MODx Content Manager - PHP/4.4.4" in your headers is indicating that you’re not using PHPMailer class.

                  The international characters are not showing correctly because the mail is still sent without the correct Content Type utf-8.

                  Using the PHPMailer class for sending mails would output these headers:

                  X-Mailer: PHPMailer [version 1.73]
                  MIME-Version: 1.0
                  Content-Transfer-Encoding: 8bit
                  Content-Type: text/plain; charset="UTF-8"
                  


                  I assume you did not implement the function sendMailMessage correctly in save_user.processor.php, as described here: http://modxcms.com/forums/index.php/topic,19669.0.html

                  I’m posting here the complete modified file. Rename the existing save_user.processor.php in the /manager/processors/ directory of your modx installation. Then change the extension from the attached file from txt to php and upload it to your server.


                  René,

                  At my server, I renamed my original save_user.processor.php to something else. Then I uploaded your file to my server and changed the extension to php. Then I tested it with the "forgot password" option. The email arrived but the headers still show: X-Mailer: MODx Content Manager - PHP/4.4.7

                  Any hints?

                  Thanks.
                    • 21496
                    • 225 Posts
                    I was checking the class.phpmailer.php itself (you can find it in in /manager/includes/controls/) to see if I did modify something there and forgot it. But that seems not to be the case, as I find in line 803 the following code:

                            $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");


                    So that’s from where it gets the information for setting the X-Mailer, and this leaves me without any clue what in your case is setting the X-Mailer to "MODx Content Manager - PHP/4.4.7". I’m using version 0.9.6.1 of MODx.

                    Well, I was reading the whole thread again, and possibly the problem is that I was testing with manager users (sending new password) and you’re testing with web users. The web users are processed by save_web_user_processor.php, so I guess you need to modify the sendMailMessage function in that file too.

                    So check with the modified save_web_user_processor.txt, or try sending a new password for manager users.
                      René
                      • 18878
                      • 210 Posts
                      Well, I uploaded the file save_web_user.processor.php and tested it from the website (frontend), but the headers are still coming like this: X-Mailer: MODx Content Manager - PHP/4.4.7

                      I also tested the manager password reminder. The headers arrive like this:

                      Content-type: text/html; charset=iso-8859-1
                      X-Mailer: PHP/4.4.7

                      but... the special chars are garbled. I noticed that in this case, the email text is obtained from manager\includes\lang\spanish.inc.php. I checked this file and everything is ok, specials chars look fine, and the file is UTF-8.

                      I don’t know what’s wrong huh