【问题标题】:My PHP contact form is shooting blanks我的 PHP 联系表是空白
【发布时间】:2011-09-13 02:41:12
【问题描述】:

请原谅这个诙谐的标题,但我在过去的一个小时里一直在努力让我的联系表正常工作。它可以很好地发送电子邮件,但会遗漏所有相关数据(姓名、电子邮件等)

我修改了一个 PHP 联系表单教程,但我不知道我哪里出错了。

HTML:

<form name="form1" method="post" action="send_contact.php">
<fieldset>
    <h3>Name</h3>
    <input name="name" type="text" id="name">

    <h3>Email (required)</h3>
    <input name="email" type="text" id="email">

    <h3>Phone (required)</h3>
    <input name="telephone" type="text" id="telephone">

    <h3>Desired appointment time/date</h3>
    <input name="time" type="text" id="time">

    <input type="submit" name="Submit" value="Submit">

</fieldset>
</form>

PHP:

<?php
// customer name
$customer_name = "$name";
// customer email
$mail_from = "$email";
// customer telephone
$customer_telephone = "$telephone";
// desired appointment time
$appointment_time = "$time";

// subject
$subject = "Appointment for $customer_name";
// message
$message = "$customer_name would like to book an appointment for $appointment_time";
// header
$header = "from: $customer_name <$mail_from>";
// recipient
$to = 'my@emailaddress.com'; 

$send_contact = mail($to,$subject,$message,$header);

if($send_contact){
    echo "We've recived your contact information";
}
else {
    echo "ERROR";
}
?>

【问题讨论】:

    标签: php forms contact contact-form


    【解决方案1】:

    你不需要引号。

    $customer_name = "$name";
    $customer_name = $name;
    

    你真的应该使用 post 来获取数据。

    $customer_name = $_POST['name'];
    

    【讨论】:

      【解决方案2】:

      您需要在超级全局 $_POST 中查找您的变量。例如

      $customer_name = $_POST['name'];
      

      【讨论】:

        【解决方案3】:

        如果您发布需要从帖子中获取的数据:我也会对其进行修剪

        $customer_name = trim( $_POST['name'] );
        

        【讨论】:

        • 修剪有什么作用? $_POST 正是我所需要的。谢谢!
        • trim 删除前导空格和训练空格(如果有)。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-04
        • 1970-01-01
        • 2015-11-05
        • 1970-01-01
        • 2018-09-11
        • 2013-06-09
        • 1970-01-01
        相关资源
        最近更新 更多