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