在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') ;
?>
答案 0 :(得分:3)
来自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;
答案 1 :(得分:2)
请在您的代码中添加以下内容:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";