dqyitt2954 2019-08-09 09:21
浏览 81

无法从会话设置电子邮件变量,因此mail()函数无法正常工作

I'm very new to php and sql and I'm trying to set a _SESSION variable for my user_email, I know that the column name is correct and I'm pulling the other information from the session like the user_id etc correctly but cannot seem to get the email to set even though I've done it the same as my other variables. I'm also trying to use the mail() function but I'm not sure if this is set up correctly? Any help would be really appreciated!

I've tried doing the variable as a _POST one using a hidden input but that hasn't worked either.

    <div>

    <?php

    if (isset($_POST['request_date'])) {

    $user_email = $_SESSION['user_email'];
    $user_id = $_SESSION['user_id'];
    $first_name = $_SESSION['first_name'];
    $last_name = $_SESSION['last_name'];
    //  $request_time = date("d-m-Y H:i:s");
    $lend_status = 1;
    $requested_start_date = date('Y-m-d H:i:s', strtotime($_POST['requested_start_date'] . ' ' . $_POST['requested_start_time'] . ':00:00'));
    $requested_end_date = date('Y-m-d H:i:s', strtotime($_POST['requested_end_date'] . ' ' . $_POST['requested_end_time'] . ':00:00'));
    $comments = $_POST['comments'];


    // Declare available laptops array
    $available_laptops = array();

    // GET ALL LAPTOPS IN OPERATION
    $STH = $DBH->prepare("
        SELECT laptop_id,
        laptop_name
        FROM laptops
        WHERE 1
    ");
    $STH->execute(array());

    while ($row = $STH->fetch()) {

        // CHECK EACH LAPTOP FOR THE REQUESTED DATES
        $STH2 = $DBH->prepare("
            SELECT lend_id
            FROM laptop_system
            WHERE (
                (
                    approved_start_date <= ?
                    AND approved_end_date >= ?
                ) OR (
                    approved_start_date <= ?
                    AND approved_end_date >= ?
                ) OR (
                    approved_start_date >= ?
                    AND approved_end_date <= ?
                )
            )
            AND laptop_id = ?
        ");
        $STH2->execute(array(
            $requested_start_date,
            $requested_start_date,
            $requested_end_date,
            $requested_end_date,
            $requested_start_date,
            $requested_end_date,
            $row->laptop_id
        ));

        // IF IT'S NOT BOOKED OUT, ADD TO ARRAY
        if ($STH2->rowCount() < 1) {
            $available_laptops[$row->laptop_id] = $row->laptop_name;
        }
    }

    if (empty($available_laptops)) {

        echo '<h3>Sorry, this date is not available.</h3>';

    } else {

        $STH = $DBH->prepare("
            INSERT INTO laptop_system (
                user_id,
                first_name,
                last_name,
                lend_status,
                requested_start_date,
                requested_end_date,
                comments
            )
            VALUES(?, ?, ?, ?, ?, ?, ?)
        ");
        $STH->execute(array(
            $user_id,
            $first_name,
            $last_name,
            $lend_status,
            $requested_start_date,
            $requested_end_date,
            $comments
        ));

        echo '<h2 style="color:#D80B8C; margin-bottom:1em;">' . $first_name . ', your laptop request is now pending approval.</h2>';



        $to = $user_email;
        $subject = "Laptop Request";
        $message = "Thank you for your laptop request for " . $requested_start_date . " - " . $requested_end_date . "It is now pending and you will be notified if it's been approved or declined.";
        $message = wordwrap($message,70);
        $headers = "From: Timmy and Edwardo";

        mail($to,$subject,$txt,$headers);

    }

    } ?>


    <form action="" method="post" >

    <div>
      <label for="requested_start_date"> Requested Start Date </label>
      <input type="date" name="requested_start_date" value="<?php echo $requested_start_date; ?>">

        <label for="requested_start_time">Requested start time </label>
            <select name="requested_start_time" style="width:auto;margin:1em 1em 1em 0;">
                <?php   for ($i = 0; $i < 25; $i++) {$i = str_pad($i, 2, "0", STR_PAD_LEFT);  ?>
                    <option value="<?php echo $i; ?>"><?php echo $i . ':00'; ?></option>
                <?php } ?>
            </select>
    </div>

    <div>
      <label for="requested_end_date">Requested End Date </label>
      <input type="date" name="requested_end_date" value="<?php echo $requested_end_date; ?>">

        <label for="requested_end_time">Requested end time</label>
            <select name="requested_end_time" style="width:auto;margin:1em 1em 1em 0;">
                <?php   for ($i = 0; $i < 25; $i++) {$i = str_pad($i, 2, "0", STR_PAD_LEFT);  ?>
                            <option value="<?php echo $i; ?>"><?php echo $i . ':00'; ?></option>
                <?php } ?>
            </select>
        </div>

        <div>
            <p style="margin-bottom:0;">
                Please can you let us know below why you need the laptop and if there are any special requirements needed -
            </p>
          <input type="textarea" rows="4" cols="50" name="comments" placeholder="" required>
            <input type="submit" name="request_date" value="Request Date">
        <!--    <input type="hidden" name="user_email" value="<?php echo $user_email;?>" > -->
        </div>


    </form>


    <?php
    ?>
    </div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号