简体   繁体   English

当我单击联系表单中的“提交”按钮时,没有任何反应

[英]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的问题,但会解决以下问题:

  • if a mail() call error occurs, it will be logged, and a message will be displayed (which will also confirm the email address involved) 如果发生mail()调用错误,它将被记录并显示一条消息(这还将确认所涉及的电子邮件地址)
  • single-quoted strings don't have to be parsed by the PHP interpreter and should be used unless you are embedding variables or character sequences (such as "\\n" ) that need to be interpreted 单引号的字符串不必由PHP解释器解析,除非在嵌入需要解释的变量或字符序列(例如"\\n" )时使用,否则应使用单引号
  • you won't be generating bad HTML by having text written to the browser before the <head> section of the document 通过在文档的<head>部分之前将文本写入浏览器,您将不会生成错误的HTML
  • you will be assured the correct action is being used to handle the form 您将确信正在使用正确的action来处理表格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在我使用Ajax和PHP构建的表单中,单击“提交”按钮后没有任何反应 - Nothing happens after I click on submit button, in my form built in Ajax and PHP 单击表单html按钮时没有任何反应 - nothing happens when click on a form html button 单击我的提交按钮没有_POST值时没有任何反应 - nothing happens when clicking on my submit button no _POST values 单击提交按钮时,PHP Ajax联系人表单重复错误 - Php Ajax contact form repeat errors when click on submit button 单击提交按钮时联系表不起作用 - Contact form not working while click on submit button 单击按钮时,表单提交无效 - form submit is not working when i click button 我的联系表格有什么问题,一旦我点击提交按钮,它就一直说发生错误! 请再试一次 - what is wrong with my contact form, once i click the submit button it keep saying Error occurd! Please try again 当我在电子邮件联系表单上点击“提交”时,显示代码 - code displays when i hit submit on my email contact form Wordpress 上的“我的提交”按钮联系表未发送 - My Submit button on Wordpress Contact form is not sending CodeIgniter表单助手-单击提交时没有任何反应 - CodeIgniter form helper - nothing happens when clicking on submit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM