Send an html mail with php


Some time ago I have found and used a lot the function below to send UTF-8 html mails.
Basically we use the php mail function with the header set to utf and the content type set to html.



//***************** Mail with UTF8 support **************//
function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') 
{
   $header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
   mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header);
}
//***************** Mail with UTF8 support **************//


As an example you can use the function like this:
mail_utf8($_SESSION['user_email'],$subject, $body, $headers);

where $body will be the body of the message and $headers are the headers with other info like
$headers  = "From: YouRent.gr\r\n";
$headers .= "Reply-To: info@yourent.gr\r\n";
$headers .= "Return-Path: info@yourent.gr\r\n";
$headers .= 'MIME-Version: 1.0' . "\n";

Σχόλια

Δημοφιλείς αναρτήσεις