Send Email in UTF-8

Wikitechy | 4244 Views | php | 13 Jun 2016

 

  • A simple UTF-8(Unicode Transformation Format) mail sender function is mainly used to encode subject and plain-text message to UTF-8.
  • If we need to send the HTML mail form text/plain to text/html, this function is usable but in most cases without any modification. Here is the simple function we use to send email in UTF-8.

Sample Script For Sending Email In Utf-8:

<?php
function mail_utf8($to, $from_user, $from_email,  $subject = '(No subject)', $message = '')

    $from_user = "=?UTF-8?".base64_encode($from_user)."?=";
    $subject = "=?UTF-8?".base64_encode($subject)."?=";
    $headers = "From: $from_user <$from_email>\r\n". "MIME-Version: 1.0" . "\r\n" .  "Content-type: text/html; charset=UTF-8" . "\r\n"; 
    return mail($to, $subject, $message, $headers); 
}
?>

Applies to:

  • PHP 3 and 4
  • PHP 5
  • PHP 6 and Unicode
  • PHP 7

Related Tags:

  • php - How to send UTF-8 email?
  • How to send correct UTF-8 mail in PHP
  • Send encoded mail - PHP
  • Unicode and email  in PHP
  • Using UTF-8 characters on an e-mail subject 
  • php email utf 8
  • mail utf 8
  • php mail utf 8 subject
  • php mail charset utf-8
  • phpmailer utf-8
  • utf 8 email address
  • email encoding utf-8



Workshop

Bug Bounty
Webinar

Join our Community

Advertise
<