Jump to content

sending mail error in thai language


martenBoy
 Share

Recommended Posts

Hello,

 

I am trying to install a shop in Thai language with prestashop 1.6.0.14 but I have an exception complaining about e-mail subject validation.

 

I have tried to install  EASY FIX THAI for PrestaShop 1.6.0.14 by devstore but that did not help. here is the full log

 

I just wonder if I have add any other validator somewhere.

 

 

Property Mail->subject is not valid
at line 872 in file classes/ObjectModel.php

867. 868. 			$message = $this->validateField($field, $this->$field);869. 			if ($message !== true)870. 			{871. 				if ($die)872. 					throw new PrestaShopException($message);873. 				return $error_return ? $message : false;874. 			}875. 		}876. 877. 		return true;

 

and the buggy code here

 

            if ($send && Configuration::get('PS_LOG_EMAILS'))
            {
                $mail = new Mail();
                $mail->template = substr($template, 0, 62);
                $mail->subject = substr($subject, 0, 254);
                $mail->id_lang = (int)$id_lang;
                foreach (array_merge($to_list->getTo(), $to_list->getCc(), $to_list->getBcc()) as $recipient)
                {
                    $mail->id = null;
                    $mail->recipient = substr($recipient->getAddress(), 0, 126);
              here is the bug //      $mail->add();
                }
            }

 

 

This exception happens in Contact us form and validation payment and every time the function validateFields is called.

Edited by martenBoy (see edit history)

Share this post


Link to post
Share on other sites

just to mention that I have found the cause of the problem it s the function inside  the class ValidateCore

 

 

    public static function isMailSubject($mail_subject)
    {
        return preg_match(Tools::cleanNonUnicodeSupport('/^[^<>]*$/u'), $mail_subject);
    }
 

could anyone tell what is the pattern I should use so it will accept Thai characters.

Edited by martenBoy (see edit history)

Share this post


Link to post
Share on other sites

What is email subject in thai? 

I found the cause of the bug but not the solution if the total email subject character length exceeds 100 characters then this issue is produced, this bug happens everywhere in payment confirmation or in contact form.

Share this post


Link to post
Share on other sites

so if Tools::strlen($mail_subject) > 254  then the bug is triggered.

so if I choose a long shop name the I have the bug

string(254) "[demoshop | สาธิตชื่อร้านค้า สาธิตชื่อร้านค้า สาธิตชื่อร้านค้า สาธิตชื่อร้านค้า สาธิตชื่อร้านค้�"
 

so far I had to add    $mail_subject = substr($mail_subject, 0, 253); so solve the issue but i am not so sure if it s the right thing to do.

Edited by martenBoy (see edit history)

Share this post


Link to post
Share on other sites

Or you will try change field size at table ps_mail.subject more than 254

yes if I increase the field size in the DB and change the max limit in Mail.php has solved the issue but

I think i found the real cause which is the lines

 

                $mail = new Mail();

                $mail->template = substr($template, 0, 62);

                $mail->subject = substr($subject, 0, 254);

                $mail->id_lang = (int)$id_lang;

 

as long as the email subject size is less then the max value then things works fine.

 

I guess there is something is wrong with trimming the text when it is oversize so if I simply change it to

$mail->subject = substr($subject, 0, 253); it will works fine, i have checked the resulted Thai text and it has the Unicode FFFD

at the end of the trimmed string.

 

string(254) ยืนยันการสั่�"

 

note that this bug is never produced when I use English version even if I choose very long shop name.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More