简体   繁体   English

带有html内容的电子邮件功能

[英]e-mail function with html content

i am trying to send e-mail with html code inside. 我试图发送带有html代码的电子邮件。 i have following code; 我有以下代码;

$message ="<html><head><title></title></head><body>test</body></html>"; 
$rmail = $mail_email;
$subject = "subject";
$head = "MIME-Version: 1.0 ";
$head .= "Content-type: text/html; charset=utf8";           
$head .= "Date: ".date("r")." ";
$mail_at=mail($rmail, $subject, $message, $head);

but, when i open the mail, mail content is, 但是,当我打开邮件时,邮件内容是

<html><head><title></title></head><body>test</body></html>

it is just sending the string not compile the html code. 它只是发送字符串而不编译html代码。

You need to add newlines in your header 您需要在标题中添加换行符

 $head = "MIME-Version: 1.0 \r\n";
 $head .= "Content-type: text/html; charset=utf8 \r\n";           
 $head .= "Date: ".date("r")." \r\n";

Otherwise the Content-type header is on the same line as MIME-version which won't work 否则, Content-type标头与MIME-version位于同一行,这将不起作用

Mostly \\r\\n works for me but I've seen some servers where it only works with \\n 大多数情况下, \\r\\n对我有用,但是我已经看到一些服务器只能在\\n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM