添加 PHP 以形成电子邮件回复

Adding PHP to form email response

我希望表单输入 (http://besthomebuildercoloradosprings.com/) 中的 'name' 显示在自动回复电子邮件中(在单词 'Congratulations' 之后)。尽管插入了 <?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 双引号中的文字字符串中,因此您根本不需要标记。双引号字符串中的变量会自动插入。只需将 <?php echo $name; ?> 替换为 $name 就可以了。

在你的情况下 <?php echo $name; ?> 在 PHP 中使用 PHP。这没有意义:

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

最好简单地使用 {$name}:

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

或使用string concatenation:

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