将PHP添加到表单电子邮件响应中


Adding PHP to form email response

我想要表单输入中的"name"(http://besthomebuildercoloradosprings.com/)显示在自动回复电子邮件中(在单词"祝贺"之后)。尽管插入了<?php echo $name; ?>,但它目前没有显示在我的html中。我浏览了所有的论坛并进行了实验,但没有任何效果。

以下是我的webformmailer.php文件的内容:

          <?php
      $name = $_POST['name'];
      $email = $_POST['email'];
      $phone = $_POST['phone'];
      $bonus = $_POST['bonus'];
      $formcontent=" Hello, 'n 'nThis email has been sent to you from the Challenger Homes BestHomeBuilderColoradoSprings.com contact form. 'n 'n From: $name 'n Phone: $phone 'n Email: $email 'n Bonus: $bonus 'n";
      $recipient = "sally@superfinedesigns.com";
      $subject = "New lead from Challenger Homes!";
      $mailheader = "From: sally@superfinedesigns.com 'r'n";
      mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
      header("Location: http://www.besthomebuildercoloradosprings.com/thankyou.html");
      $headers  = 'MIME-Version: 1.0' . "'r'n";
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
      @mail($email, $email_subject, $replymsg, $headers);

      $replymsg = "
      <html>
      <head>
      <title>Your Challenger Certificate</title>
      </head>
      <body>

      <table style='cell-padding:0px; cell-spacing:0px; border-collapse:collapse; border:0px; border-spacing:0px; padding:0px; margin: 0 auto;'>
      <tr>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert1.jpg'>
      </td>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert2.jpg'>
      </td>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert3.jpg'>
      </td>
      </tr>
      <tr>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert4.jpg'>
      </td>
      <td width='434px' style='background-color:#f4f4f2; border:0px; padding:0px;'>
      <strong>Congratulations <?php echo $name; ?> ! </strong>
      <br><br>
      Thank you for registering with Challenger Homes. You are eligible for incredible and exclusive internet savings. Present this certificate at any Challenger Model Home to get started! Or call today to schedule an appointment: 719-602-5824.
      <br><br>
      We are here to serve you and help make life better for you in a brand-new Challenger Home!
      </td>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert6.jpg' style='display:block;'>
      </td>
      </tr>
      <tr>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert7.jpg' style='display:block;'>
      </td>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert8.jpg' style='display:block;'>
      </td>
      <td  style='border:0px; padding:0px;'>
      <img src='http://www.besthomebuildercoloradosprings.com/images/cert9.jpg' style='display:block;'>
      </td>
      </tr>
      </table>


      </body>
      </html>
      "
      ;
      $email_subject = "Your Special Internet Savings from Challenger Homes";
      mail($email, $email_subject, $replymsg, $headers);
      ?>

在您的案例中,<?php echo $name; ?>在PHP中使用PHP。这没有道理:

<?php
$name = "test";
$replymsg = "<?php echo $name; ?>";

最好简单使用{$name}:

<?php
$name = "test";
$replymsg = "Blah blah {$name} and more.";

或者使用字符串串联:

<?php
$name = "test";
$replymsg = "Blah blah " . $name . " and more.";

该标记位于双引号的PHP文本字符串中,因此您根本不需要标记。双引号字符串中的变量会自动插入。只要把<?php echo $name; ?>换成$name,你就会好起来。