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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)