我并不真正使用 PHP,而且這樣做超出了我的能力范圍。我正確設置了 XAMPP 及其“sendmail”文件夾,以便我可以從我創(chuàng)建的網站發(fā)送電子郵件。電子郵件會發(fā)送給該人,但問題是,每當我第一次發(fā)送郵件后嘗試刷新時,網頁都會告訴我“您正在查找您輸入的已使用信息的頁面。返回到該頁面可能會導致您所采取的任何行動被重復”。因此,如果我單擊“繼續(xù)”,頁面會刷新,但郵件會再次發(fā)送。我嘗試使用標頭進行重定向,但它并沒有真正起作用。我收到一條錯誤,指出“無法修改標頭信息 - 標頭已發(fā)送”。我也嘗試過一些AJAX功能但沒有成功。我真的無法理解這個問題,我現在非常感謝一些幫助這是我的表單 HTML <form method="post" action="#" class="contact-form" autocomplete="off"> <div class="row"> <div class="col span-1-of-3"> <label for="name">Name</label> </div> <div class="col span-2-of-3"> <input type="text" name="name" id="name" placeholder="Your name" required> </div> </div> <div class="row"> <div class="col span-1-of-3"> <label for="email">Email</label> </div> <div class="col span-2-of-3"> <input type="email" name="email" id="email" placeholder="Your email" required> </div> </div> <div class="row"> <div class="col span-1-of-3"> <label for="find-us">How did you find about us?</label> </div> <div class="col span-2-of-3"> <select name="find-us" id="find-us"> <option value="friends" selected>Friends</option> <option value="search">Seach Engine</option> <option value="other">Other</option> </select> </div> </div> <div class="row"> <div class="col span-1-of-3"> <label>Newsletter</label> </div> <div class="col span-2-of-3"> <input type="checkbox" name="newsletter" id="newsletter" checked>Yes, please </div> </div>
1 回答

HUWWW
TA貢獻1874條經驗 獲得超12個贊
您需要使用POST/REDIRECT/GET 模式將用戶重定向到另一個頁面或同一頁面以避免這種情況。發(fā)送303 HTTP 響應將告訴瀏覽器替換其歷史記錄中的該頁面,并避免重新發(fā)送已發(fā)布的數據。
if (mysqli_query($connection, $register)) {
? ? if(isset($_POST['sendmail'])){
? ? ? ? mail($_POST['email'], 'Store' , 'Thanks for the message '.$_POST['name'].' !');
? ? ? ? header('Location: index.php', true, 303);
? ? ? ? exit;
? ? }
? ? else {
? ? ? ? // Handle error
? ? }
}
這是一個非?;镜睦?。您將需要為調用添加錯誤檢查/處理,mail()因為它可能會失敗。您還應該有某種消息傳遞方式讓用戶知道電子郵件已發(fā)送。
- 1 回答
- 0 關注
- 177 瀏覽
添加回答
舉報
0/150
提交
取消