[FX.php List] Email with accents
Lindal, Mark
mlindal at pfc.forestry.ca
Tue Aug 14 08:39:19 MDT 2007
Hi Bob,
I just got the message and have lots of experience with this email and
french accent problem. Being from Canadian Government, we have to send
email in French and English, so I have worked this problem to death.
After banging my head against a wall I found the keys to unlocking the
problem:
1. UTF-8 for the PHP page and email scripts (was using FM6 at the time so
had to deal with iso-8859-1 at the same time)
2. Email message must be in HTML.
3. after trying every PHP function - the only one I needed was stripslashes.
Here is the code for the Email script:
function sendEmailWithSockets ($toName, $toEmail, $subject, $message)
{
global $SMTPServer, $SMTPPort, $emailFromName, $emailFromAddr,
$contactEmailAddr, $email;
$connect = fsockopen($SMTPServer, $SMTPPort, $errno, $errstr, 30) or
die("$errno: $errstr");
$rcv = fgets($connect, 1024);
fputs($connect, "HELO {$_SERVER['SERVER_NAME']}\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "MAIL FROM:{$emailFromAddr}\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "RCPT TO:{$toEmail}\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "DATA\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "Subject: $subject\r\n");
fputs($connect, "From: {$emailFromName} <{$emailFromAddr}>\r\n");
fputs($connect, "To: {$toName} <{$toEmail}>\r\n");
fputs($connect, "X-Sender: <{$emailFromAddr}>\r\n");
fputs($connect, "Return-Path: <{$emailFromAddr}>\r\n");
fputs($connect, "Errors-To: <{$emailFromAddr}>\r\n");
fputs($connect, "X-Mailer: PHP\r\n");
fputs($connect, "X-Priority: 3\r\n");
// had to change this to text/html to make it work
fputs($connect, "Content-Type: text/html; charset=utf-8\r\n");
fputs($connect, "\r\n");
// important to stripslashes out of message
fputs($connect, stripslashes($message)." \r\n");
fputs($connect, ".\r\n");
$rcv = fgets($connect, 1024);
fputs($connect, "RSET\r\n");
$rcv = fgets($connect, 1024);
fputs ($connect, "QUIT\r\n");
$rcv = fgets ($connect, 1024);
fclose($connect);
}
If you need more help contact me and I can help you solve this.
------------------------------
Mark Lindal
Publications Technician / Technicien, publications
Canadian Forest Service / Service canadien des forêts
Natural Resources Canada / Ressources naturelles Canada
Government of Canada / Gouvernement du Canada
506 West Burnside Road / 506, chemin Burnside ouest
Victoria, BC V8Z 1M5 / Victoria (C.-B.) V8Z 1M5
mlindal at nrcan.gc.ca
250-363-0603
More information about the FX.php_List
mailing list