2

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

<?php
ob_start();
$to = "me@mymail.com";
$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 = "mail@yourdomain.co.in";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: http://yourdomain.co.in') ;
?>
4

2 回答 2

3

来自PHP 邮件函数文档

// 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;
于 2013-08-14T11:14:09.353 回答
2

请在您的代码中添加这一行:

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

http://www.w3schools.com/php/func_mail_mail.asp

于 2013-08-14T11:15:45.167 回答