note 62275 added to function.mail

From: Date: Thu, 23 Feb 2006 22:34:49 +0000
Subject: note 62275 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-104328@lists.php.net to get a copy of this message
If you would like to send an email with non-ASCII characters in the subject (or any other header), this function will convert it into a 7 bit QP-encoded string that works with almost all mail clients (you are NOT allowed to send raw 8 bit data in a header, and even if you did there would be no way to know which charset was used). This function takes a UTF-8 string in $s. If your PHP pages are in ISO-8859-1, just replace "=?UTF-8?Q?" with "=?ISO-8859-1?Q?" below. <?php function encodeMimeSubject($s) { $lastspace=-1; $r=""; $buff=""; $mode=1; for ($i=0; $i<strlen($s); $i++) { $c=substr($s,$i,1); if ($mode==1) { $n=ord($c); if ($n & 128) { $r.="=?UTF-8?Q?"; $i=$lastspace; $mode=2; } else { $buff.=$c; if ($c==" ") { $r.=$buff; $buff=""; $lastspace=$i; } } } else if ($mode==2) { $r.=qpchar($c); } } if ($mode==2) $r.="?="; return $r; } function qpchar($c) { $n=ord($c); if ($c==" ") return "_"; if ($n>=48 && $n<=57) return $c; if ($n>=65 && $n<=90) return $c; if ($n>=97 && $n<=122) return $c; return "=".($n<16 ? "0" : "").strtoupper(dechex($n)); } ?> ---- Server IP: 194.246.101.61 Probable Submitter: 138.195.152.183 ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62275 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62275&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62275&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104328) next »