Send.php没有显示表单的内容

时间:2014-01-14 13:46:41

标签: php

所以我终于得到了反馈表,正在工作并向我的电子邮件地址发送电子邮件,但我有另一个问题。表格的内容没有显示,不知道有什么不对。我是php的新手,所以我很确定它很简单..发布下面的代码

<?php 
 $name = $_POST ['name'];
 $mail = $_POST ['mail'];
 $number = $_POST ['number'];
 $feedback = $_POST ['feedback'];

 $to = 'ATotallyRandom@Email.net';
 $subject = 'Feedback from atetaconsult.com';
 $msg = "Your name: $name\n" .
 " Your email: $email\n" .
 " Feedback: $feedback\n";

 mail ($to, $subject, $msg, 'From:' . $email);

 echo ' thank you <br/>';
 echo ' your name ' .$name .'<br/>';
 echo ' Your email ' . $email .'<br/>';
 echo ' Your feedback ' . $feedback . '<br/>';

 ?>

表单的HTML代码也在下面

<form method="post" action="send.php">
    <p class="head" style="font-style: italic; color: #fff; line-height: 24px; font-size: 19px; margin-bottom: 47px; margin-top: 20px; font-family: Lato, sans-serif;">
                We’d love to hear from you. Interested in working together? Fill out the form below with some info about your project and I will get back to you as soon as I can. Please allow a couple days for me to respond.</p>
    <div class="row form">
        <input id="name" class="name" type="text" placeholder="Name">
        <input id="mail" class="mail" type="text" placeholder="Email">
        <input id="number" class="phone" type="text" placeholder="Phone">
    </div>
    <div class="span6 box box_r">
        <textarea id="feedback" rows="6" class="span6" placeholder="Type a message here..."></textarea>
    </div> 
    <div class="btn" style="margin-top:5px;">
        <input type="submit" value="Send your message">
    </div>
  </form><div style="clear: both;"></div>

3 个答案:

答案 0 :(得分:0)

将所有这些代码放在:

之间
if($_POST){

// Your coding

}

同时向我展示您在联系表格中使用的Javascript / Jquery编码。

答案 1 :(得分:0)

下面:

$msg = "Your name: $name\n" .
" Your email: $email\n" .
 " Feedback: $feedback\n";

您要求变量$ email

但您已将其指定为顶部的$ mail。

请参阅:http://markpetherbridge.co.uk/StackOverflow/phpmail.php?name=Mark&mail=test@test.com&feedback=testfeedback

为了演示目的,我已将其更改为$ email并将类型更改为$ _GET,但它似乎正在运行。试试吧。

以下是该文件的完整代码:

<?php 
 $name = $_GET ['name'];
 $email = $_GET ['mail'];
 $number = $_GET ['number'];
 $feedback = $_GET ['feedback'];

 $to = 'ATotallyRandom@Email.net';
 $subject = 'Test from Mark P';
 $msg = "Your name: $name\n";
 $msg .= " Your email: $email\n";
 $msg .= " Feedback: $feedback\n";

 mail ($to, $subject, $msg, 'From:' . $email);

 echo ' thank you <br/>';
 echo ' your name ' .$name .'<br/>';
 echo ' Your email ' . $email .'<br/>';
 echo ' Your feedback ' . $feedback . '<br/>';

 ?>
 <br /><br />
 Here is the result from $msg: <br /><br />
 <?php 

 echo $msg;

 ?>

您需要在html中添加名称:

    <input name="name" id="name" class="name" type="text" placeholder="Name">
    <input name="mail" id="mail" class="mail" type="text" placeholder="Email">
    <input name="number" id="number" class="phone" type="text" placeholder="Phone">

答案 2 :(得分:0)

您尚未在输入上设置名称值。

更改:

<form method="post" action="send.php">
    <p class="head" style="font-style: italic; color: #fff; line-height: 24px; font-size: 19px; margin-bottom: 47px; margin-top: 20px; font-family: Lato, sans-serif;">
                We’d love to hear from you. Interested in working together? Fill out the form below with some info about your project and I will get back to you as soon as I can. Please allow a couple days for me to respond.</p>
    <div class="row form">
        <input name="name" id="name" class="name" type="text" placeholder="Name">
        <input name="mail" id="mail" class="mail" type="text" placeholder="Email">
        <input name="number" id="number" class="phone" type="text" placeholder="Phone">
    </div>
    <div class="span6 box box_r">
        <textarea name="feedback" id="feedback" rows="6" class="span6" placeholder="Type a message here..."></textarea>
    </div> 
    <div class="btn" style="margin-top:5px;">
        <input type="submit" value="Send your message">
    </div>
  </form><div style="clear: both;"></div>