我在網站上有一個發送消息的表格,消息應該發送到一個電子郵件地址。由于我是網站建設的新手,所以我正在玩,但無法讓表格與 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="[email protected]" 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 = '[email protected]'; $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 = "[email protected]"; $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>
您必須像上面的代碼一樣在所有輸入標簽中添加名稱屬性...
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消