douyanti2808 2014-07-03 00:30
浏览 36
已采纳

联系表单 - 仅问题:PHP未返回INPUT

I have been working with this for a couple days and have read thru MANY previously posed questions, as well as several tutorial sites... The Contact Form submits, confirms and redirects... It sends the email, with headers and subject line, to correct address... just NO inputs... no "FROM SENDER EMAIL", no FROM NAME INPUT, no EMAIL INPUT, no MESSAGE INPUT... HELP! So close, and yet so far... any advice is greatly appreciated ~ I write HTML & CSS, novice at JS and practically NO PHP experience... Thank You in Advance! :)

Here's the HTML contact-form:

 <form action= "contact-form.php" id="contact-form" method="post">
                            <fieldset>
                                <label><input name="cf-name" type="text" value="Your     Name" onBlur="if(this.value=='') this.value='Your Name'" onFocus="if(this.value =='Your     Name' ) this.value=''" /></label>
                                <label>
                                <input name="cf-email" type="text" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" />
                                </label>
                        <textarea name="cf-message" onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message</textarea>
                                <div class="buttons">
                                    <p><a href="#" onClick="document.getElementById('contact-form').reset()">Clear</a>
                                      <a href="#" onClick="document.getElementById('contact-form').submit()">Send</a></p>
                                    <p>&nbsp;
                                        </p>
                                </div>                                          
                          </fieldset>           
                        </form>

and here is the PHP (contact-form.php):

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'info@anelectrician.net';
$subject = 'Message from a website visitor...'.$field_name;

$body_message = 'From:'.$field_name."
";
$body_message .= 'E-mail:'.$field_email."
";
$body_message .= 'Message:'.$field_message;

$headers = 'From: '.$field_email."
";
$headers .= 'Reply-To: '.$field_email."
";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
    alert('Thank you for your correspondence. We will contact you shortly.');
    window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
    alert('Message failed. Please, send an email to info@anelectrician.net');
    window.location = 'contact.html';
</script>
<?php
}
?>
  • 写回答

4条回答 默认 最新

  • douquanqiao6788 2014-07-03 00:32
    关注

    You seem to have a difference here... In PHP you are using underscores and in HTML you are using dashes.

    You can always test what is going wrong and where your code is by debugging with:

    print_r($_POST);
    

    That should help you figure out if you are just not using the correct keys.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集