[英]Why does my page stay blank after I press submit?
<form method="post" action="mail_handler.php"> <div class="col-sm-7 slideanim"> <div class="row"> <div class="col-sm-6 form-group"> <input class="form-control" id="name" name="name" placeholder="Naam" type="text" required> </div> <div class="col-sm-6 form-group"> <input class="form-control" id="phone" name="phone" placeholder="Telefoonnummer" type="text" required> </div> <div class="col-sm-12 form-group"> <input class="form-control" id="email" name="email" placeholder="Email" type="email" required> </div> </div> <textarea class="form-control" id="msg" name="msg" placeholder="Bericht" rows="5"></textarea><br> <div class="row"> <div class="col-sm-12 form-group"> <button class="btn btn-default pull-right" id="submit" type="submit">Verstuur</button> </div> </div> </div> </div> </div> </form>
我試圖使此表單正常工作,但是由於某種原因,它只是不發送電子郵件,而且在我按下“提交”按鈕后,它仍然保持空白。 我已盡力修復所有問題,但我一直忽略這一點。 (我與Cpanel一起檢查郵件是否正在發送,因此有可用的smtp服務器)。
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='info@sync-development.nl'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Bedankt voor uw bericht!"." ".$name.", Wij nemen zo snel mogelijk contact met u op.</h1>";
}
else{
echo "Er is iets fout gegaan, probeer het alstublieft opnieuw.";
}
}
?>
您應該在按鈕上添加名稱屬性,以便替換
<button class="btn btn-default pull-right" id="submit" type="submit">Verstuur</button>
通過
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>`
嘗試這個
<button class="btn btn-default pull-right" name="submit" id="submit" type="submit">Verstuur</button>
<button class="btn btn-default pull-right" id="submit" type="submit">Verstuur</button>
您缺少名稱屬性,並且php處理程序無法進入if true條件,因為它找不到“ submit”鍵。 像這樣更改您的HTML按鈕 :
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>
您可以將name =“”屬性添加到按鈕,也可以中繼其他變量。 同樣,使用!empty()
仔細檢查傳遞的變量是否不是空字符串。
因此,請替換:
if(isset($_POST['submit'])){
有:
if (!empty($_POST['email'])){
或者簡單地:
if (!empty($_POST)){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.