php - 联系方式文件不起作用

标签 php javascript html

在我的网站上,我有一个自动联系公式,它在我的本地主机服务器上运行,但如果我将文件加载到我的服务器上,它将无法工作。提交似乎不起作用,它不会抛出错误消息,只是重新加载页面。我已经做了很多代码审查,但到目前为止还没有发现任何问题。 对我来说奇怪的是,代码在我的本地主机上运行,​​但在服务器上不起作用......

您可以在这里自己测试一下:

http://144.76.1.46/RequestStream.php

代码如下:

<?php 
$your_email ='censored@gmail.com';

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['Submit']))
{

    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $user_message = $_POST['message'];
    ///------------Do Validations-------------
    if(empty($name)||empty($visitor_email))
    {
        $errors .= "\n Name and Email are required fields. ";   
    }
    if(IsInjected($visitor_email))
    {
        $errors .= "\n Bad email value!";
    }
    if(empty($_SESSION['6_letters_code'] ) ||
      strcmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
    {
    //Note: the captcha code is compared case insensitively.
    //if you want case sensitive match, update the check above to
    // strcmp()
        $errors .= "\n The captcha code does not match!";
    }

    if(empty($errors))
    {
        //send the email
        $to = $your_email;
        $subject="New form submission";
        $from = $your_email;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

        $body = "A user  $name submitted the contact form:\n".
        "Name: $name\n".
        "Email: $visitor_email \n".
        "Message: \n ".
        "$user_message\n".
        "IP: $ip\n";    

        $headers = "From: $from \r\n";
        $headers .= "Reply-To: $visitor_email \r\n";

        mail($to, $subject, $body, $headers);

        header('Location: thank-you.html');
    }
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
     // censored
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Contact Us</title>   
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="censored" type="text/javascript"></script>   
</head>

<body>
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
<p>
<label for='name'>Streamname: </label><br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
<p>
<label for='email'>Your Email: (for possible further queries) </label><br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>
<p>
<label for='message'>Streamlink and explanation why he should be listed on Lol Streamgalleries: (preferably with links to reliable sources (such as leagepedia for example)</label> <br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
<p>
<img src="html-contact-form-captcha/captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input type="submit" value="Submit" name='submit'>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
    var img = document.images['captchaimg'];
    img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</body>
</html>

编辑: 错误控制台对我有一点帮助,javascript 文件存在引用错误,现在修复了它,但遗憾的是仍然无法工作。

最佳答案

您将按钮命名为submit,但检查了$_POST['Submit']

尝试isset($_POST['提交'])

$_POST['submit'] == 'Submit'

关于php - 联系方式文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14413854/

相关文章:

jquery - 剖析 img src 属性

javascript - 在 HTML5 Canvas 中拖放多个对象

html - 过渡持续时间在特定的 div 中不起作用

php - Cookie 嗅探器 - PHP

javascript - jquery 中的 onclick(function(){}) 和 on ('click' ,function(){}) 函数有什么区别

Javascript选择单选按钮更改php函数

刷新时重新生成 PHP session_id

javascript - node.js 中高效的闭包结构

javascript - react 冗余 Prop 验证

javascript - 确定拆分两个 TextFrame 是否会在 InDesign 中拆分一个段落