发送HTML并在电子邮件中对其进行格式化

时间:2012-03-27 00:57:21

标签: php html email

我正在创建一个在线商店,我想发送一个电子邮件收据...我已经使用php mail()函数将原始html发送到正确的电子邮件地址,但这就是原始的html ...是有一种方法,电子邮件客户端(Gmail)将此视为一个Web布局

目前,当电子邮件客户端收到它时,它看起来像这样

<HTML><BODY><TABLE class = product cellpadding = 0 cellsspacing = 0 border = 0 width = 
100%><tr><td width = 50 height = 60><a href="shopProcessCart.php?action=delete&id=3" 
class="r"><img src="inc/remove.png" border="0" alt="Remove"></a></td><td>Cape Clear
 History Part 2</td><td width = 70>&euro;14.99</td><td width = 40><input type="number" 
name="qty3" value="1" size="2" maxlength="2" /></td></TABLE><p>Total: 
<strong>&euro;14.99</strong></p></BODY></HTML>

2 个答案:

答案 0 :(得分:1)

您必须设置html标题

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

并将其作为php的mail()函数中的参数传递

邮件($ to,$ subject,$ message,$ headers);

答案 1 :(得分:1)

您只需将标题设置为html电子邮件:

    $to = "email@example.com"; 
    $from = "email2@example.com"; 
    $subject = "Hello! This is HTML email"; 

    //begin of HTML message 
    $message = <<<EOF 
<html> 
  <body bgcolor="#DDDDDD"> 
    YOUR HTML EMAIL
  </body> 
</html> 
EOF; 
   //end of message 
    $headers  = "From: $from\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html\r\n"; 

    mail($to, $subject, $message, $headers);