我必须编写以下代码才能在我的网站中使用 PHP 发送邮件,该网站托管在 Linux 服务器上。邮件已发送,但消息以原始 HTML 而不是标记文本的形式发送。这是代码:
<?php
sendMail('name@domain.tld', 'Your recovered password', 'Your password is <b>ABC123</b>', 'kush.impetus@gmail.com');
function sendMail($from='name@domain.tld', $subject, $message, $to = 'name@domain.tld'){
$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();
}
?>
如何更正代码以正确发送 HTML 邮件?
提前致谢