简体   繁体   English

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

[英]Sending HTML and format it in the email

Im creatingan online shop and i want to send an email receipt... I've gotten raw html to be sent to the correct email address using the php mail() function but thats all it is raw html... Is there a way that the email client (gmail) will see this as a web layout 我正在创建一个网上商店,我想发送一个电子邮件收据...我已经使用php mail()函数将原始的HTML发送到正确的电子邮件地址,但这就是原始的HTML ...有没有办法电子邮件客户端(gmail)会将此视为Web布局

At the moment it looks like this when the email client receives it 目前,当电子邮件客户端收到它时,它看起来像这样

<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>

You will have to set html headers 您将不得不设置html标头

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

And pass it as a parameter in php's mail() function 并将其作为php的mail()函数中的参数传递

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

You just have to set the header to html email: 您只需将标头设置为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); 

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

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