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.

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

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端