我在使用PHP邮件通过多页表单进程传递$ _SESSION变量时遇到问题。尽管电子邮件没有显示变量,但电子邮件还是很顺利。 我的目标是让用户在多个页面上填写表单,并将数据通过电子邮件发送给我。
第1页
<?php
session_start();
?>
<form method="post" action="submitpage.php">
<label>
<input type="radio" name="vehicle_type" value="car" checked />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="suv" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="van" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="truck" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
<label>
<input type="radio" name="vehicle_type" value="none" />
<img class="img-responsive" src="img/vehicle2.png">
</label>
</form>
第2页
<?php
session_start();
$_SESSION['vehicle_type'] = $_POST['vehicle_type'];
?>
<form method="post" action="emailexample.php" id="submit-form">
<input type="Email" name="email">
<input type="submit" name="submit" value="Submit" id="submitbtn">
</form>
第3页
<?php
session_start();
$to = 'myemail@gmail.com';
$subject = 'test ';
$message = "Your Vehicle Type is: " . $_POST['vehicle_type'] ."\r\n";
$headers = 'From: email@example.com' . "\r\n" .
mail($to, $subject, $message, $headers);
?>
答案 0 :(得分:0)
第3页
使用$ _SESSION [&#39; vehicle_type&#39;]代替$ _POST [&#39; vehicle_type&#39;]
答案 1 :(得分:0)
在第1页上,你应该把提交按钮放在这样的
<input type="submit" name="submit" value="Submit" />
在第3页上,您应该更改
$message = "Your Vehicle Type is: " . $_SESSION['vehicle_type'] ."\r\n";
你最后在$ headers变量中丢失了分号。它应该是
$headers = 'From: email@example.com' . "\r\n";