mail() - spanish accents
Moderator: General Moderators
-
alexislalas
- Forum Commoner
- Posts: 44
- Joined: Sun Feb 19, 2006 10:09 pm
mail() - spanish accents
hello.
my website is in spanish, and im sending a mail with the mail() function, but dont know how to put the accents. is there a way, like in html?
thanks
my website is in spanish, and im sending a mail with the mail() function, but dont know how to put the accents. is there a way, like in html?
thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
You can use HTML entities, or you can send your email in UTF-8 format. Swift Mailer will manage the encoding for you if you're sending such characters since SMTP has certain restrictions on this -- particularly in the headers such as the subject line.
If it is a plain text email use the following headers:
As for the subject line:Saludos
Code: Select all
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bitCode: Select all
$subject = 'Español';
$charset = 'ISO-8859-1';
$subject_encoded = '=?'.$charset.'?B?' . base64_encode($subject) . '?=';
print $subject_encoded;- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
That doesn't work if you saved the file as UTF-8 with your editor. Tried and tested with a lot of hairs pulled out.bokehman wrote:If it is a plain text email use the following headers:
As for the subject line:Code: Select all
Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bitSaludosCode: Select all
$subject = 'Español'; $charset = 'ISO-8859-1'; $subject_encoded = '=?'.$charset.'?B?' . base64_encode($subject) . '?='; print $subject_encoded;
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Yeah, basically you need to make sure the charset matches that of the charset it was saved in.bokehman wrote:Which bit? I don't really see your point, the email should be saved as it would be sent... not in some alien format.d11wtq wrote:That doesn't work if you saved the file as UTF-8 with your editor. Tried and tested with a lot of hairs pulled out.
Also, if the SMTP server does not support 8BITMIME you need to base64 or quoted-printable encode the entire email.
Here's how I handle it:
Detecting for UTF-8 ( Graçias in UTF-8 is not the same as Graçias in iso-8859-1 (editor settings) )
Code: Select all
/**
* Detect if a string contains multi-byte non-ascii chars that fall in the UTF-8 tanges
* @param mixed input
* @return bool
*/
public function detectUTF8($string_in)
{
foreach ((array)$string_in as $string)
{
if (preg_match('%(?:
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)+%xs', $string)) return true;
}
return false;
}For the message body I apply the same principle by checking if it;'s UTF-8 then setting the charset of the email to UTF-8.
For the 8BITMIME issue (some servers will deny your email if it's contains characters outside the 7-bit asciii range since it doesn't fall into the generic SMTP implementation) I do this where $string is the ESMTP extension list of the server:
Code: Select all
/**
* Check if the server allows 8bit emails to be sent without quoted-printable encoding
* @param string EHLO response
*/
private function check8BitMime($string)
{
if (strpos($string, '8BITMIME')) $this->_8bitmime = true;
}I see what you are getting at now. When a mail client sends an email it waits for the result of the EHLO before building the mail. And then builds the email based on that response. But what happens if a mail exchanger further down the chain finds the coding unacceptable? Does the sending mail exchanger rewrite the email to a different format?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Glad you askedbokehman wrote:Does the sending mail exchanger rewrite the email to a different format?
The good MTAs do recode the email to make it supported. The bad ones do not or at least, they do it wrongly.
Read this: http://en.wikipedia.org/wiki/8BITMIME