为了账号安全,请及时绑定邮箱和手机立即绑定

用于网站发送消息表单的 action.php

用于网站发送消息表单的 action.php

PHP
婷婷同学_ 2023-03-26 14:42:07
我在网站上有一个发送消息的表格,消息应该发送到一个电子邮件地址。由于我是网站建设的新手,所以我正在玩,但无法让表格与 action.php 文件一起使用。当我将 HTML 代码和 action-page.php 上传到服务器(在同一子文件夹中)时,我在网站上键入的消息根本没有发送。我没有收到电子邮件,当我单击发送按钮时,我被转发到浏览器中的空白页面。最好我只停留在同一页面上并收到“您的消息已发送”通知,但这是一个“不错的”我只是想让它工作。我使用: https: //html.form.guide/email-form/php-form-to-email.html作为代码的参考。1. 哪里出了问题或为什么不起作用?网站留言表单代码如下:<div class="o-screen-contact__col-form">    <form class="c-form js-form-validation" action="action-page.php" method="post">      <label for="contact-name">Jouw naam</label>      <input class="c-form__field" id="contact-name" type="text" placeholder="Bijvoorbeeld, Jade van de Ven" required>      <label for="contact-email">Jouw e-mail</label>      <input class="c-form__field" id="contact-email" type="email" placeholder="Jouwemail@email.nl" required>      <label for="contact-message">Jouw bericht</label>      <textarea class="c-form__field" id="contact-message" name="name" placeholder="Schrijf hier jouw bericht of zorg" required></textarea>      <fieldset class="u-text-right">        <button class="c-button c-button--primary" type="submit" name="contact-submit">Zend mij een bericht</button>      </fieldset>    </form>  </div>我使用 post 方法并为要发送到电子邮件地址的实际消息制作了一个 action-page.php 文件。action-page.php 文件如下所示:<?php$name = $_POST['contact-name'];$visitor_email = $_POST['contact-email'];$message = $_POST['contact-message'];?><?php    $email_from = 'zorg@ontzorg-zwolle.nl';    $email_subject = "Nieuwe email website ontzorg-zwolle";    $email_body = "You have received a new message from the user $contact-name.\n".                        "Here is the message:\n $contact-message".?><?php  $to = "zorg@ontzorg-zwolle.nl";  $headers = "From: $email_from \r\n";  $headers .= "Reply-To: $visitor_email \r\n";  mail($to,$email_subject,$email_body,$headers);?>2. action-page.php文件放在服务器的什么地方我已将 action-page.php 文件与 index.html 文件(消息表单所在的位置)放在同一文件夹中。那是正确的地方吗?或者我是否需要将文件放在其他地方才能正确调用?
查看完整描述

1 回答

?
呼唤远方

TA贡献1856条经验 获得超11个赞

您已正确完成所有操作,但您错过了输入标签中的 name 属性。

你的代码应该是这样的,

<input class="c-form__field" id="contact-name" name="contact-name" type="text" placeholder="Bijvoorbeeld, Jade van de Ven" required>

您必须像上面的代码一样在所有输入标签中添加名称属性...


查看完整回答
反对 回复 2023-03-26
  • 1 回答
  • 0 关注
  • 77 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信