Php 用于输出HTML电子邮件的联系人表单-电子邮件中未输入数据

Php 用于输出HTML电子邮件的联系人表单-电子邮件中未输入数据,php,html,email,Php,Html,Email,我一直在开发一个联系人表单,它可以输出一封html电子邮件,然后通过电子邮件发送到某个地址。这个过程运行得很好,但它并没有将数据放入html电子邮件中供收件人阅读 <?php if(isset($_POST['submit'])) { //create an empty errors array $errors = array(); //our form has been submitted if($_POST['name'] == "") { //the

我一直在开发一个联系人表单,它可以输出一封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;

在$message变量上使用双引号,如
$message=“…”
在$message中需要使用双引号。

设置
$message
变量时,使用单引号(')来分隔字符串。这会导致php不解析字符串中的变量。您可以使用双引号(“)代替:

$message = "<html><body>Name: $name</body></html>";
$message=“Name:$Name”;
或者像这样连接字符串:

$message = '<html><body>Name: '.$name.'</body></html>';
$message='Name:'.$Name';