note 80466 modified in function.mail by danbrown

From: Date: Sat, 25 Apr 2009 14:57:39 +0000
Subject: note 80466 modified in function.mail by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153729@lists.php.net to get a copy of this message
send e-mail in utf-8 there is already a solution from omgs. but with a longer subject line there could be problem (splitting the subject line in a encoded character). here my solution: <?php // hmm no better solution? function imap8bit(&$item, $key) { $item = imap_8bit($item); } function email($e_mail, $subject, $message, $headers) { // add headers for utf-8 message $headers .= "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=utf-8\r\n"; $headers .= "Content-Transfer-Encoding: quoted-printable\r\n"; // encode subject //=?UTF-8?Q?encoded_text?= // work a round: for subject with wordwrap // not fixed, no possibility to have one in a single char $subject = wordwrap($subject, 25, "\n", FALSE); $subject = explode("\n", $subject); array_walk($subject, imap8bit); $subject = implode("\r\n ", $subject); $subject = "=?UTF-8?Q?".$subject."?="; // encode e-mail message $message = imap_8bit($message); return(mail("$e_mail", "$subject", "$message", "$headers")); } ?> --was-- send e-mail in utf-8 there is already a solution from omgs. but with a longer subject line there could be problem (splitting the subject line in a encoded character). here my solution: ---- // hmm no better solution? function imap8bit(&$item, $key) { $item = imap_8bit($item); } function email($e_mail, $subject, $message, $headers) { // add headers for utf-8 message $headers .= "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=utf-8\r\n"; $headers .= "Content-Transfer-Encoding: quoted-printable\r\n"; // encode subject //=?UTF-8?Q?encoded_text?= // work a round: for subject with wordwrap // not fixed, no possibility to have one in a single char $subject = wordwrap($subject, 25, "\n", FALSE); $subject = explode("\n", $subject); array_walk($subject, imap8bit); $subject = implode("\r\n ", $subject); $subject = "=?UTF-8?Q?".$subject."?="; // encode e-mail message $message = imap_8bit($message); return(mail("$e_mail", "$subject", "$message", "$headers")); } http://php.net/manual/en/function.mail.php

« previous php.notes (#153729) next »