从电子邮件中的PHP表单发布数据

时间:2013-05-07 15:13:01

标签: php html5 forms

我正在尝试在向电子邮件发送数据时向我的电子邮件中添加更多变量。

<?php
$to = "opsafehaven@enhstudios.com";
$email = $_POST['email'];
$fname = $_POST['first'];
$lname = $_POST['last'];
$account = $_POST['account'];
$subject = "Safe Haven Reservation";
$message = $account;
$from = $email;
$headers = "From:" . $from;
mail($to,$subject,$fname,$lname,$account);
?>

我希望能够添加;消息的$ fname和$ lname,我无法弄清楚要处理的字符数。

3 个答案:

答案 0 :(得分:0)

您应该将表单方法设置为POST,如此

<form name="reservations" action="reservations.php" method="post">

现在你将能够收到邮件!而已!

您的错误在于您错误地设置了表单元素的属性!您应该使用method="post"代替method="get"

答案 1 :(得分:0)

更改表单帖子类型getpost

<form name="reservations" action="reservations.php" method="post">

答案 2 :(得分:0)

这些是您应该做出的改变:(这可能会也可能不会起作用,手指交叉)

<?php
    $to = "opsafehaven@enhstudios.com";
    $email = $_POST['email'];

    $fname = $_POST['first'];
    $lname = $_POST['last'];

    $account = $_POST['account'];
    $subject = "Safe Haven Reservation";

    $message = $fname." ".$lname."\n".$account;

    $from = $email;
    $headers = "From:" . $from;
    mail($to,$subject,$message);
?>