如何让我的PHP联系表单工作?

时间:2014-08-07 12:19:48

标签: php forms

我有一个我从this forum开发的php联系表单,该表单从网站上获取客户姓名,电子邮件和联系电话,但是我收到了几个错误说;第34行的未定义索引名称,同样的错误也出现在许多其他变量中,我想知道我是否可以帮助解决这个问题?

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $Contact_Number = $_POST['contact number'];
    $from='From:Client';
    $to='reece@designthink.co.uk';
    $subject='Claremont Holding Page Enquiry';
    $body = "From: $name\n E-Mail: $email\n Contact Number:\n $Contact_Number";

if($_POST['submit'])
{
    if(mail($to, $subject,$body,$from))
    {
        echo '<p>Message sent!</p>';
    }
    else
    {
        echo '<p> something went wrong, please try again!</p>';
    }

}

?>



<form method = "post" action ="Index.php">

<label> name </label>
<input name="Name" placeholder="Type Here">


<label> email </label>
<input name="email" placeholder="Type Here">

<label> contact number </label>
<input name="Contact Number" placeholder="Type Here">

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


</form>

1 个答案:

答案 0 :(得分:-2)

post变量的索引应该与表单输入元素名称

相同

更正您的表单(更改元素名称)

<form method = "post" action ="Index.php">

<label> name </label>
<input name="name" placeholder="Type Here">


<label> email </label>
<input name="email" placeholder="Type Here">

<label> contact number </label>
<input name="contact_umber" placeholder="Type Here">

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


</form>

AND php

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name']; // use here the same name as in input elements of form
    $email = $_POST['email'];
    $Contact_Number = $_POST['contact_number'];
    $from='From:Client';
    $to='reece@designthink.co.uk';
    $subject='Claremont Holding Page Enquiry';
    $body = "From: $name\n E-Mail: $email\n Contact Number:\n $Contact_Number";


    if(mail($to, $subject,$body,$from))
    {
        echo '<p>Message sent!</p>';
    }
    else
    {
        echo '<p> something went wrong, please try again!</p>';
    }

}

?>