我正在使用bootstrap contact form.表单工作正常但无论我做什么我都无法发送html电子邮件。我已经添加了标题和css内联到脚本的不同部分,但它从不发送任何HTML格式的电子邮件。我正撞在墙上,非常感谢任何帮助。我在哪里放置标头变量,我在哪里放置html?
这是php代码。
<?php
if ($_POST["submit"]) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Mywebsite';
$to = 'me@email.com';
$subject = 'Contact Email ';
$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "To: ". $to. "\r\n";
$headers .= "From: ". $from;
$body = " $headers, From: $name\n E-Mail: $email\n Message: $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if content has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! </div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>
这是HTML。
<div style="padding:10px; background:#000; font-size:46px; font-weight: 900; color:#fff; ">
My Website
</div>
<div style="padding:24px; font-size:17px; background:#DCDCDC ; ">
This is a message from My website.
<br>
<br>
<br>
<a href="http://www.mywebsite.com">Login in to your account</a>
<br>
<br>
</div>
<br>
<br>
</div>
答案 0 :(得分:3)
将mail($to, $subject, $body, $from);
替换为mail($to, $subject, $body, $headers);