[英]Nothing happens when i click on submit button in my contact form
When I click on the submit button, nothing happens, even though I do have PHP set up. 当我单击提交按钮时,即使设置了PHP,也没有任何反应。 I thought at first that my code is obviously wrong.
起初我以为我的代码显然是错误的。 But now I even copy/pasted the code from here, that is checked as correct, yet nothing happens.
但是现在我什至从这里复制/粘贴了代码,将其检查为正确,但没有任何反应。
Here is that code: 这是该代码:
<?php
if(isset($_POST['submit'])){
$to = "zezesurla@gmail.com"; // 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>
Could this be a problem that is in the server and not the actual code? 这可能是服务器中的问题,而不是实际的代码吗? Because I tried several other examples that I found on various tutorials and the same issue occurs.
因为我尝试了在各种教程中发现的其他几个示例,并且发生了相同的问题。
Or am I still doing something wrong? 还是我做错了什么?
As a minimum, I would make the following changes to your code: 至少,我将对您的代码进行以下更改:
<?php
$msg='';
if (isset($_POST['submit']))
{
... ...
if (!mail($to,$subject,$message,$headers))
error_log(($msg='Send form submission to "'.$to.'" failed'));
else if (!mail($from,$subject2,$message2,$headers2)) // sends a copy of the message to the sender
error_log(($msg='Send copy of form submission to user "'.$from.'" failed'));
else $msg='Mail Sent. Thank you ' . $first_name . ', we will contact you shortly.';
... ...
<body>
<?php if ($msg)
{ ?>
<p><?php echo $msg ?></p>
<?php
} ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
These changes will not address the problem of the form being vulnerable to sending SPAM, but it will address these issues: 这些更改不会解决表单易于发送SPAM的问题,但会解决以下问题:
mail()
call error occurs, it will be logged, and a message will be displayed (which will also confirm the email address involved) mail()
调用错误,它将被记录并显示一条消息(这还将确认所涉及的电子邮件地址) "\\n"
) that need to be interpreted "\\n"
)时使用,否则应使用单引号 <head>
section of the document <head>
部分之前将文本写入浏览器,您将不会生成错误的HTML action
is being used to handle the form action
来处理表格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.