简体   繁体   中英

e-mail function with html content

i am trying to send e-mail with html code inside. 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.

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

Mostly \\r\\n works for me but I've seen some servers where it only works with \\n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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