PHP Send UTF-8 mail without PEAR :: Mail PEAR :: Mail_Mime

I would like to be able to send emails using PHP mail () containing 8 bit Γ₯Àâ characters. They will be used in the subject, message, and From: header. How can I do this without using PEAR packages?

+2


source to share


3 answers


The simplest solution, if you don't mind encoding even words that are not needed, is all that needs to be done in RFC 2047 base64 encoding:



$subject= "=?utf-8?b?".base64_encode($subject)."?=";
$body= "blah blah $utf8text blah";
$headers= "MIME-Version: 1.0\r\n";
$headers.= "From: =?utf-8?b?".base64_encode($fromname)."?= <$fromaddress>\r\n";
$headers.= "Content-Type: text/plain;charset=utf-8";

mail($toaddress, $subject, $body, $headers);

      

+4


source


Use the swiftmailer library. http://swiftmailer.org/



0


source


$headers = array('From' => $from,
    'To' => "<$to>",
    'Subject' => $subject);

if ($is_html) {
    $headers['Content-type'] = "text/html; charset=UTF-8";
} else {
    $headers['Content-type'] = "text/plain; charset=UTF-8";
}

      

This works for me

-2


source







All Articles