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

我在网站上有一个发送消息的表格,消息应该发送到一个电子邮件地址。

由于我是网站建设的新手,所以我正在玩,但无法让表格与 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 文件(消息表单所在的位置)放在同一文件夹中。那是正确的地方吗?或者我是否需要将文件放在其他地方才能正确调用?


婷婷同学_
浏览 121回答 1
1回答

呼唤远方

您已正确完成所有操作,但您错过了输入标签中的 name 属性。你的代码应该是这样的,<input&nbsp;class="c-form__field"&nbsp;id="contact-name"&nbsp;name="contact-name"&nbsp;type="text"&nbsp;placeholder="Bijvoorbeeld,&nbsp;Jade&nbsp;van&nbsp;de&nbsp;Ven"&nbsp;required>您必须像上面的代码一样在所有输入标签中添加名称属性...
打开App,查看更多内容
随时随地看视频慕课网APP