Jump to content

zend mail character set


Illasera

Recommended Posts

I suppose you could also create an HTML email, and simply have it contain text. If it must look like text, and be formatted as one, you could always wrap it up with a pre element, like:

$transport = new Zend_Mail_Transport_Smtp();$mail = new Zend_Mail('UTF-8');$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);$mail->setBodyHTML('<pre>' . htmlspecialchars('Text with Кирилица (Cyrillic) in it.', ENT_NOQUOTES, 'UTF-8') . '</pre>', 'UTF-8', Zend_Mime::ENCODING_BASE64);$mail->setFrom('example@fromDomain.com', 'From Name');$mail->addTo('example@gmail.com');$mail->setSubject('Кирилица demo');$mail->send($transport);

The second argument of setBodyHTML should implicitly create a meta element with the charset, as by the old system.

Link to comment
Share on other sites

I suppose you could also create an HTML email, and simply have it contain text. If it must look like text, and be formatted as one, you could always wrap it up with a pre element, like:
$transport = new Zend_Mail_Transport_Smtp();$mail = new Zend_Mail('UTF-8');$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);$mail->setBodyHTML('<pre>' . htmlspecialchars('Text with Кирилица (Cyrillic) in it.', ENT_NOQUOTES, 'UTF-8') . '</pre>', 'UTF-8', Zend_Mime::ENCODING_BASE64);$mail->setFrom('example@fromDomain.com', 'From Name');$mail->addTo('example@gmail.com');$mail->setSubject('Кирилица demo');$mail->send($transport);

The second argument of setBodyHTML should implicitly create a meta element with the charset, as by the old system.

Hmmm yea, i figured that , But thanks mate,But i didn`t quite get that part, can you explain how do you combine php variables within the SetBodyHTML?Sorry for the lack of understanding..
Link to comment
Share on other sites

htmlspecialchars() takes a string, and escapes all characters in it that are special in HTML. Namely, "&", "<" and ">". This ensures that whatever text you've given to it, it will be displayed like that. Without this function, the text is interpreted as HTML, so if the text contains "<b>something</b>", to the client, it will be seen as a bolded text that says "something". With this function, the client would see "<b>something</b>" as "<b>something</b>", i.e. the same way you're seeing it now.The second parameters says that the function will not escape single and double quotes. In this case, we don't need them escaped, because this is HTML text. If you had the text in an attribute's value, you'll probably want to escape quotes as well.The third argument specifies the charset of the string, inputted as the first argument. This is really important, as the output string will be in that charset too. Because we use UTF-8 everywhere, and the whole HTML document is also going to be using UTF-8, we must ensure the function returns UTF-8 text, so we specify UTF-8 as the third argument.Finally, the string is wrapped around with a pre element. This is done with string concatenation. The end result becomes a pre element with text in it. All HTML we may have inputted is displayed as plain text.
Link to comment
Share on other sites

htmlspecialchars() takes a string, and escapes all characters in it that are special in HTML. Namely, "&", "<" and ">". This ensures that whatever text you've given to it, it will be displayed like that. Without this function, the text is interpreted as HTML, so if the text contains "<b>something</b>", to the client, it will be seen as a bolded text that says "something". With this function, the client would see "<b>something</b>" as "<b>something</b>", i.e. the same way you're seeing it now.The second parameters says that the function will not escape single and double quotes. In this case, we don't need them escaped, because this is HTML text. If you had the text in an attribute's value, you'll probably want to escape quotes as well.The third argument specifies the charset of the string, inputted as the first argument. This is really important, as the output string will be in that charset too. Because we use UTF-8 everywhere, and the whole HTML document is also going to be using UTF-8, we must ensure the function returns UTF-8 text, so we specify UTF-8 as the third argument.Finally, the string is wrapped around with a pre element. This is done with string concatenation. The end result becomes a pre element with text in it. All HTML we may have inputted is displayed as plain text.
Thank you for the paremeters info. That proved to be helpfullThank you so much mate, That solved my problem, Thank you, Thank You, Thank you,I think to solve my problem without HTML format, would be set the php mail with content-language, Its a shame i have no idea how to do it, But that will do :)
Link to comment
Share on other sites

I thought you'd figure it out already... don't you remember the addHeader() method? I mentioned it so many times now, as a "manual override" of everything else. It would be the same for Content-Language, i.e.

$mail->addHeader('Content-Language', 'en-us');//Or whatever your language is

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...