dth981485742 2016-02-21 07:42
浏览 64

我的PHP联系表单无法正常工作。 发送部分信息

I am new to PHP but have a site that I need to go live and I cant get the form to work.

Basically what it does is send JUST whats in the "message" field. All other fields are blank for some reason. Also, if possible, I would like help getting it to put a confirmation of "sent mail" without redirecting to a new page, but rather just a pop up message in the form itself.

So here is the code.

<form method="post" action="index.php">
    <div class="form-group">
        <input class="form-control" name="name" placeholder="Name" type="text">
    </div>
    <div class="form-group">
        <input class="form-control" name="email" placeholder="Email" type="text">
    </div>
    <div class="form-group">
        <input class="form-control" name="text" placeholder="Which class are you interested in?" type="text">
    </div>
    <div class="form-group">
        <input class="form-control" name="phone" placeholder="What is the best number to you reach you?" type="text">
    </div>
    <div class="form-group">
        <textarea class="form-control" name="message" placeholder="Message" rows="3"></textarea>
    </div>
    <input class="btn btn-block" type="submit" name="submit" value="Submit">
</form>

and here is the PHP

<?php

$Name = $_POST['name'];
$Email = $_POST['email'];
$Class = $_POST['class'];
$Phone = $_POST['phone'];
$Message = $_POST['message'];
$from = 'From: **** Site'; 
$to = '**********@gmail.com'; 
$subject = 'Message from **** Site';

$body = "From: $Name
 E-Mail: $Email
 Class: $Class
 Phone: $Phone
      Message:
 $Message";

if ($_POST['submit']) {              
if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
}

?>

Any help here would be greatly appreciated.

  • 写回答

2条回答 默认 最新

  • doufu6504 2016-02-21 08:15
    关注

    Made one change to this code,

    <html>
    
    <form method="post" action="mail.php">
        <div class="form-group">
            <input class="form-control" name="name" placeholder="Name" type="text">
        </div>
        <div class="form-group">
            <input class="form-control" name="email" placeholder="Email" type="text">
        </div>
        <div class="form-group">
            <input class="form-control" name="class" placeholder="Which class are you interested in?" type="text">
        </div>
        <div class="form-group">
            <input class="form-control" name="phone" placeholder="What is the best number to you reach you?" type="text">
        </div>
        <div class="form-group">
            <textarea class="form-control" name="message" placeholder="Message" rows="3"></textarea>
        </div>
        <input class="btn btn-block" type="submit" name="submit" value="Submit">
    </form>
    </html>
    

    And check the PHP file,

    $Name = $_POST['name'];
    $Email = $_POST['email'];
    $Class = $_POST['class'];
    $Phone = $_POST['phone'];
    $Message = $_POST['message'];
    $from = 'From: **** Site'; 
    $to = '**********@gmail.com'; 
    $subject = 'Message from **** Site';
    
    var_dump($_POST);
    
    ?>
    

    All the variables are being passed.

    For having the answer in the same page without redirecting, use jQuery AJAX requests like this example. Use Javascript. http://www.formget.com/submit-form-using-ajax-php-and-jquery/

    I'll post the answer for your solution if you still have issues with the AJAX.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题