Is it possible to send HTML mail with php?


Is it possible to send HTML mail with php?

Yes, using the mail() function of PHP, HTML emails can be sent. The content type header must be mentioned.

<?php
// multiple recipients
$to = ‘example@example.com’
// subject
$subject = ‘HTML email’;

// message
$message = ‘
<html>
<head>
<title>HTML EMAIL</title>
</head>
<body>
<p>Sample of HTML EMAIL!</p>
</body>
</html>
‘;

// To send HTML mail, the Content-type header must be set

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;

// Additional headers
$headers .= ‘To: Joe <joe@example.com>, Kelly <kelly@example.com>’ . “\r\n”;
$headers .= ‘From: HTML EMAIL <sample@example.com>’ . “\r\n”;
$headers .= ‘Cc: samplecc@example.com’ . “\r\n”;
// Mail it
mail($to, $subject, $message, $headers);
?>

Leave a comment