Envoyer un email au format HTML Imprimer

  • 0

Pour envoyer un email au format HTML, il faut mettre l'entête au format MIME:

<?php

$to = 'email@destinataire';
$from = 'email@expéditeur';
$fromName = 'SenderName';

$subject = "Send HTML Email in PHP";

$htmlContent = '
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Thanks you for joining with us!</h1>
<table cellspacing="0" style="border: 2px dashed #FB4314; width: 100%;">
<tr>
<th>Name:</th><td>Maromania</td>
</tr>
<tr style="background-color: #e0e0e0;">
<th>Email:</th><td>email@expéditeur</td>
</tr>
<tr>
<th>Website:</th><td><a href="http://www.maromania.com">www.maromania.com</a></td>
</tr>
</table>
</body>
</html>';

// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// Additional headers
$headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n";
$headers .= 'Cc: contact@email' . "\r\n";
$headers .= 'Bcc: achraf@email' . "\r\n";

// Send email
if(mail($to, $subject, $htmlContent, $headers)){
echo 'Email has sent successfully.';
}else{
echo 'Email sending failed.';
}
?>


Cette réponse était-elle pertinente?

« Retour