douxuexiao1748 2014-08-07 12:19
浏览 41

如何让我的PHP联系表单工作? [重复]

This question already has an answer here:

I have a php contact form which I developed from this forum, the form gets a customers name, email and contact number from a website however, I'm getting several errors saying; undefined index name on line 34, the same error is present for a number of other variables also, I'm wondering if I could have some help resolving this issue?

<?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
 E-Mail: $email
 Contact Number:
 $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>
</div>
  • 写回答

1条回答 默认 最新

  • dph19153 2014-08-07 12:21
    关注

    index of the post variable should be the same as the form input elements name

    correct your form (with change name of elements)

    <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
     E-Mail: $email
     Contact Number:
     $Contact_Number";
    
    
        if(mail($to, $subject,$body,$from))
        {
            echo '<p>Message sent!</p>';
        }
        else
        {
            echo '<p> something went wrong, please try again!</p>';
        }
    
    }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图