我一直在处理一个联系表单,该表单将输出到通过电子邮件发送到地址的html电子邮件。这个过程非常有效,但它并没有将数据放在html电子邮件中供收件人阅读。
<?php
if(isset($_POST['submit'])) {
//create an empty errors array
$errors = array();
//our form has been submitted
if($_POST['name'] == "") {
//the name field is empty
$errors[] = "The Name field is empty.";
}
if($_POST['business'] == "") {
//the business field is empty
$errors[] = "The Business name field is empty.";
}
if($_POST['telephone'] == "") {
//the telephone number field is empty
$errors[] = "The Telephone Number field is empty.";
}
if($_POST['email'] == "") {
//the email field is empty
$errors[] = "The Email address field is empty.";
}
if($_POST['enquiry'] == "") {
//the enquiry field is empty
$errors[] = "The Enquiry field is empty.";
}
if(!stripos($_POST['email'], '@')) {
$errors[] = "The email address was not valid.";
}
if($_POST['antispam'] != 10) {
$errors[] = "You entered the wrong numerical answer for the anti-spam question.";
}
if(count($errors) == 0) {
// email settings
$to = 'email@address.com' . ', ';
$subject = 'Website Enquiry Form';
// headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Return-Path: email@address.com' . "\r\n";
// form details
$name = $_POST['name'];
$business = $_POST['business'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$type = $_POST['type'];
$enquiry = $_POST['enquiry'];
$message = '
<html>
<head>
<title>Website Enquiry Form</title>
</head>
<body>
The details from completed enquiry form on the website is: <br><br> <strong> $name </strong>from <strong> $business </strong> has filled the form out. The contact details for<strong> $name </strong> is<strong> $telephone </strong> and<strong> $email </strong> is the listed email address.<br><br> <strong> $type </strong> is the selected type of enquiry.<br><br> <strong>Comments:</strong><br> $enquiry <br><br>This is the end of the enquiry form.
</body>
</html>
';
if(mail($to, $subject, $message, $headers)) {
$success = true;
} else {
$success = false;
}
} else {
$success = false;
}
}
?>
这是联络查询表格的PHP。它是我之前使用的现有修改,但没有HTML输出,而“message:”中的代码曾经是:
<<<DATA
<strong>Name:</strong> $name <br>
<strong>Email:</strong> $email <br>
<strong>Why:</strong> $subject <br>
<strong>Comment:</strong> $comments<br>
DATA;
当时有效,但我尝试在HTML代码之前放置<<<DATA
并以DATA;
结尾,然后它就不起作用了。我不是真正的开发人员,所以我不知道从哪里开始。我希望有人可以指出我正确的方向。
答案 0 :(得分:1)
设置$message
变量时,您使用单引号(')来分隔字符串。这导致php在中解析字符串中的变量。您可以使用双引号(“)代替:
$message = "<html><body>Name: $name</body></html>";
或者像这样连接字符串:
$message = '<html><body>Name: '.$name.'</body></html>';
答案 1 :(得分:0)
在$ message变量上使用双引号,例如$message = "<html>...</html>"
。
答案 2 :(得分:0)
您需要在$ message中使用双引号。