PHP sending UTF8 emails

function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
  $header_ = 'MIME-Version: 1.0' . "rn" . 'Content-type: text/plain; charset=UTF-8' . "rn";
  mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}

pretty easy. or sending utf8 html emails:

function mail_utf8_html($to, $subject = '(No subject)', $message = '', $header = '') {
  $header_ = 'MIME-Version: 1.0' . "rn" . 'Content-type: text/html; charset=UTF-8' . "rn";
  mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}

then you just call mail_utf8() or mail_utf8_html() with the normal mail() arguments.

just don’t include any mime or content-type bits in your header.

Leave a Reply

Your email address will not be published. Required fields are marked *