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