I have to written the following code to send a mail using PHP in my website, which is hosted on a Linux server. The mail is sent, but the message is sent as raw HTML instead of markup text. Here's the code:
<?php
sendMail('[email protected]', 'Your recovered password', 'Your password is <b>ABC123</b>', '[email protected]');
function sendMail($from='[email protected]', $subject, $message, $to = '[email protected]'){
$message = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$subject.'</title>
</head>
<body>'.$message.'</body>
</html>';
$message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
$message = wordwrap($message, 70);
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=UTF-8";
$headers[] = "From: $from";
$headers[] = "Reply-To: $from";
$headers[] = "Subject: {$subject}";
$additional_params = "-f $from -r $from";
if(mail($to, $subject, $message, implode("\r\n", $headers)))
echo 'Mail Sent';
else
echo 'Mail NOT Sent';
exit();
}
?>
How do I correct the code to send the HTML mail correctly?
Thanks in advance