PHP邮件:如何发送HTML?

lle*_*oun 10 html php email message sendmail

下面的代码是正确发送电子邮件,但身体.我需要在消息正文中显示html而我无法做到.网络中的示例将不会发送电子邮件:(

如何修复我的代码以发送带有html的电子邮件?

万分感谢!

<?php

$to = 'mymail@mail.com';

$subject = 'I need to show html'; 

$from ='example@example.com'; 

$body = '<p style=color:red;>This text should be red</p>';

ini_set("sendmail_from", $from);

$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
  $headers .= "Content-type: text/html\r\n"; 
if (mail($to, $subject, $body, $headers)) {

  echo("<p>Sent</p>");
 } else {
  echo("<p>Error...</p>");
 }

?>
Run Code Online (Sandbox Code Playgroud)

hel*_*lle 17

将此标题用于邮件:

 $header  = "MIME-Version: 1.0\r\n";
 $header .= "Content-type: text/html; charset: utf8\r\n";
Run Code Online (Sandbox Code Playgroud)

对于内容/正文:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
... ... ...
Run Code Online (Sandbox Code Playgroud)

使用内联css命令并建议使用表格作为接口非常重要.

...

在你的邮件正文中,你需要将HTML代码放在头部和正文中

  • @Sam在邮件的情况下:是的. (2认同)