note 29038 deleted from function.mail by crell

From: Date: Tue, 12 Apr 2022 01:10:01 +0000
Subject: note 29038 deleted from function.mail by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218226@lists.php.net to get a copy of this message
Note Submitter: f dot touchard at laposte dot net ---- ***Encoding plain text as quoted-printable in MIME email*** If you don't want to install IMAP and use imap_8bit() to encode plain text or html message as quoted-printable (friendly french special characters encoding :-) in MIME email, try this function. I haven't fully tested it ( like with microtime with long mails). I send html message as 7-bit, so I didn't try yet with html. If you have good html practise, you don't really need to encode html as quote-printable as it only uses 7-bit chars. F.Touchard <?php function qp_encoding($Message) { /* Build (most polpular) Extended ASCII Char/Hex MAP (characters >127 & <255) */ for ($i=0; $i<127; $i++) { $CharList[$i] = "/".chr($i+128)."/"; $HexList[$i] = "=".strtoupper(bin2hex(chr($i+128))); } /* Encode equal sign & 8-bit characters as equal signs followed by their hexadecimal values */ $Message = str_replace("=", "=3D", $Message); $Message = preg_replace($CharList, $HexList, $Message); /* Lines longer than 76 characters (size limit for quoted-printable Content-Transfer-Encoding) will be cut after character 75 and an equals sign is appended to these lines. */ $MessageLines = split("\n", $Message); $Message_qp = ""; while(list(, $Line) = each($MessageLines)) { if (strlen($Line) > 75) { $Pointer = 0; while ($Pointer <= strlen($Line)) { $Offset = 0; if (preg_match("/^=(3D|([8-9A-F]{1}[0-9A-F]{1}))$/", substr($Line, ($Pointer+73), 3))) $Offset=-2; if (preg_match("/^=(3D|([8-9A-F]{1}[0-9A-F]{1}))$/", substr($Line, ($Pointer+74), 3))) $Offset=-1; $Message_qp.= substr($Line, $Pointer, (75+$Offset))."=\n"; if ((strlen($Line) - ($Pointer+75)) <= 75) { $Message_qp.= substr($Line, ($Pointer+75+$Offset))."\n"; break 1; } $Pointer+= 75+$Offset; } } else { $Message_qp.= $Line."\n"; } } return $Message_qp; } ?>

« previous php.notes (#218226) next »