Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP变量放入PHP邮件的正文中_Php_Variables_Phpmailer - Fatal编程技术网

将PHP变量放入PHP邮件的正文中

将PHP变量放入PHP邮件的正文中,php,variables,phpmailer,Php,Variables,Phpmailer,我试图将userTime变量放入php邮件的正文中,但我尝试的任何操作都返回空 我尝试将它放入会话变量中,并使用$\u session调用它,但不幸的是,这也失败了 有什么建议吗 <?php session_start(); $userTable = $_SESSION['userTable']; $userDay = $_SESSION['userDay']; $userTime = $_POST['userOption']; if

我试图将userTime变量放入php邮件的正文中,但我尝试的任何操作都返回空

我尝试将它放入会话变量中,并使用$\u session调用它,但不幸的是,这也失败了

有什么建议吗

    <?php
    session_start();
    $userTable = $_SESSION['userTable'];
    $userDay = $_SESSION['userDay'];
    $userTime = $_POST['userOption']; 


    if (isset($_REQUEST['email']))  {

      $admin_email = $_REQUEST['email'];
      $email = "xxxxx@xxxxxx.xxx";
      $subject = "Booking Confirmation";

      $body = "Hi ".$_POST["name"].",\n\n";
      $body .= "Your booking for ";
      $body .= $userTable;
      $body .= " on ";
      $body .= $userDay;
      $body .= " at ";

      //none of these work
      $body .= $_POST['userOption'];
      $body .= $userTime;
      $body .= $_REQUEST['usertime'];
      // ^^^^^^^^^^^^^^^^^^^^^^^^^

      $body .= " has been confirmed.\n\n";
      $body .= "Your unique booking reference is ";
      $body .= $_REQUEST['ranNum'];
      $body .= ".\n\nPlease use this when arriving or in the event of a cancellation.\n\nThanks.";

      mail("$admin_email", "$subject", $body, "From:" . $email);
        ?>
            <script type="text/javascript">
            alert("Mail sent!");
            window.location.href = "index.php";
            </script>
        <?php
      }
      else  {
    ?>

<!DOCTYPE html>

<html>
    <head>
    </head>
<body>

    <div align="center">
        <form method="post">
          Area entered:<br>
          <input type="text" name="userarea" id="userarea" value="<?php echo $userTable; ?>" disabled><br>
          Day entered:<br>
          <input type="text" name="userday" id="userday" value="<?php echo $userDay; ?>" disabled><br>
          Time entered:<br>
          <input type="text" name="usertime" id="usertime" value="<?php echo $userTime; ?>" disabled><br>
          Please enter your name:<br>
          <input type="text" name="name" id="name"><br>
          Please enter your email address:<br>
          <input type="email" name="email" id="email"><br>
          <!--the random number-->
          <input type="hidden" name="ranNum" id="ranNum" /><br>
          <button type="submit" value="Submit" class="homepageSubmit">Submit</button>
        </form>
    </div>
    </body>
</html>
<?php

警报(“已发送邮件!”);
window.location.href=“index.php”;
输入的区域:

在HTML表单中使用
disabled
,意味着它不会发送到服务器。也许可以尝试
只读
或隐藏,只将字段显示为文本


您的表单中也没有
userOption
字段。

“如果我没有很好地解释某件事,或者遗漏了某件事,请告诉我,我会尽力更好地解释。”-发布您的完整代码和详细信息。如果有疑问,请使用错误报告和var_dump.Sorry-我现在已经对其进行了编辑,并将其放入正确的代码转储中。
var_dump($\u POST)
并告诉我们它返回了什么。我没有看到您的表单中有一个名为
userOption
的字段userOption来自之前页面上的表单,因此它确实正确地填写了html表单上echo命令的值谢谢-是隐藏部分失败了。userOption实际上来自一个进入这个页面的表单。再次感谢