dqdl6469 2015-06-22 12:08
浏览 9
已采纳

简单的联系表单PHP失败[重复]

This question already has an answer here:

I'm completely new to HTML and PHP and am trying to build a simple contact form, so that users can send me a message on the contact page, which then gets directed to my email. Any ideas what I'm doing wrong here:

contact.html:

<section id="secondary">
        <form action="contact.php" method="post" class="contactform">
          Your Name<br>
          <input type="text" maxlength="100" name="cf_name" style="width: 300px" class="contactboxes"><br>
          Your E-mail<br>
          <input type="text" maxlength="100" name="cf_email" style="width: 300px" class="contactboxes"><br>
          The Reason for Contact<br>
          <textarea name="cf_message" maxlength="500" style="width: 300px" class="contactboxes"></textarea><br>
          <input type="submit" value="Send" class="sendclearbutton">
         <input type="reset" value="Clear" class="sendclearbutton">
        </form>
      </section> 

contact.php:

<?php

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

$mail_to = 'sharan@hotmail.co.uk';
$subject = 'Message from a site 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 the message. We will contact you shortly.');
        window.location = 'contact.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to sharan@hotmail.co.uk.');
        window.location = 'contact.html';
    </script>
<?php
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • dty97501 2015-06-22 12:26
    关注

    It looks fine to me, as Lance said, the only reason I can think that it wont be working is that you don't have PHP installed. Download Apache or whatever suits your computer best or use web hosting online. Do say if other code is working, though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路