PHP 邮件:如何发送 html? [英] Php mail: how to send html?
本文介绍了PHP 邮件:如何发送 html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码正确发送电子邮件,但用于正文.我需要在消息正文中显示 html,但我无法做到.网络中的示例不会发送电子邮件:(
The code below is sending an email correctly but for the body. I need to show html in the body of the message and I cannot make it. The examples in the web won't send the email :(
如何修复我的代码以发送正文中包含 html 的电子邮件?
How can I fix my code to send the email with the html in the body?
非常感谢!
<?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 . "
Reply-To: " . $from . "";
$headers .= "Content-type: text/html
";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
推荐答案
在邮件中使用这个标题:
use this header for the mail:
$header = "MIME-Version: 1.0
";
$header .= "Content-type: text/html; charset: utf8
";
对于内容/正文:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
... ... ...
使用内联 css 命令很重要,建议在界面中使用表格.
it's important to use inline css commands and recommanded to use tables for the interface.
...
在您的邮件正文中,您必须放置 带有头部和正文的 HTML 代码
In your Mail-Body you than have to put HTML code with head and body
这篇关于PHP 邮件:如何发送 html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文