通过表单将会话变量传递给使用php的邮件

时间:2015-01-07 09:54:05

标签: php forms email session-variables

我试图从3个页面的表单中发布会话变量并将其邮寄给我自己,

邮件功能正在运行(发送空电子邮件),但没有任何变量传递到电子邮件中。

感谢任何帮助。

第1页

    <?php
session_start();
include 'incs/header.php';
?>

<form id="" name="" method="POST"
    action="page2.php" class="">
    <div class=" row input-append addressWrapper" id="fieldWrapper ">
        <input id="searchTextField" type="text" name="address"
            class="form1 request-input values address search-query"
            placeholder="Enter Your Home Address">
        <input type="hidden" name="type" id="changetype-all" checked="checked">
        <input type="hidden" name="city_image" id="city_image" value="">
        <input type="hidden" name="lat" id="lat">
        <input type="hidden" name="lng" id="lng">
        <input type="hidden" name="submit" id="submit" class="">
    </div>
    <div class="row stats">
        <div class="col-md-12">
            <select name="bedrooms" class="form3">
                <option selected value="">Bedrooms</option>
                <option value="0">0</option>
                <option value="1">1</option>
                <option value="2">2</option>
            </select>
        </div>
        <div class="col-md-12">
            <select name="bathrooms" class="form3">
                <option selected value="">Bathrooms</option>
                <option value="1">1</option>
                >
            </select>
        </div>
        <div class="col-md-12 marl ">
            <select name="squareFootage" class="form3">
                <option selected value="">Square Footage</option>
                <option value="0-800">0-800</option>
            </select>
        </div>
        <button type="submit" name="next" class="btn form1 btn-success worth p1" id="next"
            value="What's It Worth?">Submit
        </button>
    </div>
</form>

第2页

<?php
session_start();
include 'incs/header.php';

$_SESSION['address'] = $address;
$_SESSION['bedrooms'] = $bedrooms;
$_SESSION['bathrooms'] = $bathrooms;
$_SESSION['squareFootage'] = $sqft;

?>

<form id="optionsform" name="MSRequest" method="POST"
    action="page3.php" class="">
    <div class="row">
        <div class="">
            <input id="email" type="email" name="email"
                placeholder="Enter Your Email">
        </div>
        <input type="hidden" name="submit" id="submit" class=" form3">
        <button type="submit" name="next" class="btn btn-success worth "
            id="next" value="What's It Worth?">Submit
        </button>
    </div>
</form>

第3页

<?php
session_start();
include 'incs/header.php';

$address = $_POST['address'];
$_SESSION['bedrooms'] = $_POST['bedroom'];
$_SESSION['bathrooms'] = $_POST['bathrooms'];
$_SESSION['squareFootage'] = $_POST['squareFootage'];
$_SESSION['email'] = $_POST['email'];


$to      = 'example@gmail.com';
$subject = 'TESTING ';
$message = $_POST['address'] ."\r\n";
$message .= $_POST['bedrooms']."\r\n";
$message .= $_POST['bathrooms']."\r\n";
$message .= $_POST['squareFootage']."\r\n";
$message .= $_POST['address']."\r\n";
$headers = 'From: email@example.com' . "\r\n" .


mail($to, $subject, $message, $headers);
?>

1 个答案:

答案 0 :(得分:0)

试试这个 第2页:

<?php
session_start();
include 'incs/header.php';

$_SESSION['address'] = $_POST['address'];
$_SESSION['bedrooms'] = $_POST['bedroom'];
$_SESSION['bathrooms'] = $_POST['bathrooms'];
$_SESSION['squareFootage'] = $_POST['squareFootage'];

?>

<form id="optionsform" name="MSRequest" method="POST"
      action="page3.php" class="">
    <div class="row">
        <div class="">
            <input id="email" type="email" name="email"
                   placeholder="Enter Your Email">
        </div>
        <input type="hidden" name="submit" id="submit" class=" form3">
        <button type="submit" name="next" class="btn btn-success worth "
                id="next" value="What's It Worth?">Submit
        </button>
    </div>
</form>

第3页:

<?php
session_start();
include 'incs/header.php';

$to      = 'example@gmail.com';
$subject = 'TESTING ';
$message = $_SESSION['address'] ."\r\n";
$message .= $_SESSION['bedrooms']."\r\n";
$message .= $_SESSION['bathrooms']."\r\n";
$message .= $_SESSION['squareFootage']."\r\n";
$headers = 'From: email@example.com' . "\r\n" .


    mail($to, $subject, $message, $headers);
?>