php - sendmail php 中正文消息的样式

标签 php html

在sendmail php中,我创建表n,如果我们填写并单击提交按钮,邮件将成功接收。我尝试了下面显示的一些示例代码,但它会打印除引号之外的所有 html 代码。现在我想添加一些样式,例如表格或粗体斜体,或者在邮件正文中的“$message”区域添加图像...任何人都可以帮忙吗?

<?php
ob_start();
$to = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91fcf4d1fce8fcf0f8fdbff2fefc" rel="noreferrer noopener nofollow">[email protected]</a>";
$subject = "Request mail";

$message = "<html><body>";
$message .= '<img src="Images/Logos/Logo_color.png" alt="Logo" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" .$Name.PHP_EOL. "</td></tr>";
$message .= "<tr><td><strong>Company Name:</strong> </td><td>" .$Company.PHP_EOL. "</td></tr>";
$message .= "<tr><td><strong>Mobil Number:</strong> </td><td>" .$Mobile.PHP_EOL. "</td></tr>";
$message .= "<tr><td><strong>Email Id:</strong> </td><td>" .$Email.PHP_EOL. "</td></tr>";
$message .= "<tr><td><strong>Address):</strong> </td><td>" .$Address.PHP_EOL. "</td></tr>";
$message .= "<tr><td><strong>State:</strong> </td><td>" .$State.PHP_EOL. "</td></tr>";
$message .= "<tr><td><strong>Edition:</strong> </td><td>" .$Edition."</td></tr>";
$message .= "</table>";
$message .= "</body></html>";

$from = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9bf6faf2f7dbe2f4eee9fff4f6faf2f5b5f8f4b5f2f5" rel="noreferrer noopener nofollow">[email protected]</a>";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: http://yourdomain.co.in') ;
?>

最佳答案

来自 PHP mail function documentation

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $from;

关于php - sendmail php 中正文消息的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230165/

相关文章:

php - 为什么我无法使用已编译和加载的 PHP pecl_http 扩展?

php - 使用 PHP 中的 LAME 将 WAV 转换为 MP3

javascript - undefined variable : _SESSION

javascript - 在文本框中显示下拉复选框中的选择计数

html - 奇怪的 :hover behavior when using rowspan

html - 我怎样才能有一个 2 列布局,其中一列具有固定宽度,另一列具有剩余宽度?

javascript - 如何用 JavaScript 覆盖整个文档

php - 如何使用关联数组编写良好的 PHP 数据库插入

javascript - 从存储过程执行备份数据库在本地有效但在生产中无效

php - Facebook PHP SDK - 注销问题