0
當我點擊提交按鈕時,即使我設置了PHP,也沒有任何反應。起初我以爲我的代碼顯然是錯誤的。但現在我甚至從這裏複製/粘貼代碼,這被檢查爲正確的,但沒有任何反應。當我點擊我的聯繫表單中的提交按鈕時,沒有任何反應
這裏是代碼:
<?php
if(isset($_POST['submit'])){
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
</div>
這會不會是服務器中的問題,而不是實際的代碼?因爲我嘗試了其他幾個我在各種教程中找到的例子,並且發生了同樣的問題。
還是我還在做錯什麼?
回顯是否打印「郵件發送」? –
請你可以在你的代碼塊開頭刪除''。 – manian
它是否顯示任何類型的錯誤,如「警告:郵件():無法連接到郵件服務器」。或者當您提交時打印某些內容? – manian