1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
// fonction d'affichage du retour à la ligne
function affichage_correct($mail)
{
if (!preg_match("#^[a-z0-9._-]+@(hotmail|live|msn).[a-z]{2,4}$#", $mail))
{
$passage_ligne = "\r\n";
}
else
{
$passage_ligne = "\n";
}
return $passage_ligne;
}
//fonction header HTML
function header_mail_html($mail_dest, $mail, $boundary)
{
// initialisation
$passage_ligne = "";
$mime = "";
$content = "";
$header = "";
// retour à la ligne
$passage_ligne = affichage_correct($mail_dest);
// version mime
$mime = "MIME-Version: 1.0".$passage_ligne;
// content-type
$content = "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
// HEADER DU MAIL
$header = $mime.$content;
return $header;
}
// fonction message (format html)
function message_mail_html($message_html, $message_txt, $mail_dest, $boundary)
{
// initialisation
$message = "";
// retour à la ligne
$passage_ligne = affichage_correct($mail_dest);
// MESSAGE DU MAIL
$message = $passage_ligne."--".$boundary."--".$passage_ligne;
$message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
$message .= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$message.= $passage_ligne.$message_txt.$passage_ligne;
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"".$passage_ligne;
$message .= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$message.= $passage_ligne.$message_html.$passage_ligne;
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
return $message;
}
// function MAIL PHP (format html)
function send_mail_html($mail_dest, $mail_exp, $sujet, $msg_html, $msg_txt)
{
// initialisation
$header = "";
$contenu = "";
// boundary utile pour le content type
$boundary = "-----=".md5(rand());
// création du header
$header = header_mail_html($mail_dest, $mail_exp, $boundary);
// Création du message.
$contenu = message_mail_html($msg_html, $msg_txt, $mail_dest, $boundary);
// Envoi du mail
mail($mail_dest,$sujet,$contenu,$header);
} |
Partager