CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: min(four, eight)?
(Example: nine)

The Note You're Voting On

Anonymous
16 years ago
I could not find a PHP function to MIME encode the name for a n email address.

Input = "Karl Müller<[email protected]>"
Output = "Karl%20M%FCller<[email protected]>"

I wrote it on my own:

<?php
// required to encode names in email addresses
// replace " " with "%20"
// replace "ü" with "%FC"
// replace "%" with "%25" etc....
// Use "%" as Delimiter for MIME
// Use "=" as Delimiter for Quoted Printable
// Input string must be UTF8 encoded
public static function EncodeMime($Text, $Delimiter)
{
$Text = utf8_decode($Text);
$Len = strlen($Text);
$Out = "";
for (
$i=0; $i<$Len; $i++)
{
$Chr = substr($Text, $i, 1);
$Asc = ord($Chr);

if (
$Asc > 0x255) // Unicode not allowed
{
$Out .= "?";
}
else if (
$Chr == " " || $Chr == $Delimiter || $Asc > 127)
{
$Out .= $Delimiter . strtoupper(bin2hex($Chr));
}
else
$Out .= $Chr;
}
return
$Out;
}
?>

<< Back to user notes page

To Top