dongming0505 2014-01-08 22:11
浏览 61
已采纳

php脚本上的函数不正确

I have a simple contact form I'm trying to implement but I'm getting an "incorrect function" error when I try to launch it. My code below is as follows, and when I click submit, it redirects to

http://mywebsite.com/contactme.php

but with the text "Incorrect function" and that's it. My debug on firefox shows the following error:

        POST http://www.mywebsite.com/v/vspfiles/contactform/contactme.php [HTTP/1.1 405 Method Not Allowed 33ms]
    13:54:52.368 The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. 
The character encoding of the page must be declared in the document or in the transfer protocol.

I am using volusion software if that helps. But I have no idea if the error is in my code or because my webhost won't allow the function. Can someone give me some insight? I have tried the "contactme.php" page with and without the doctype declared. My two files are below. I do not have an "error.htm" page.

contact.html:

<!DOCTYPE html>
<html>
<head>
<title>Contact</title>
</head>
<body >
<div id="contact-area">
            <form method="post" action="/v/vspfiles/contactform/contactme.php">
                <h3>Contact us</h3>

                <label for="Name">Name:</label>
                <input type="text" name="Name" id="Name" />

                <label for="City">City:</label>
                <input type="text" name="City" id="City" />

                <label for="Email">Email:</label>
                <input type="text" name="Email" id="Email" />

                <label for="Message">Message:</label><br />
                <textarea name="Message" rows="20" cols="20" id="Message"></textarea>

                <input type="submit" name="submit" value="Submit" class="submit-button" />
            </form>         
            <div style="clear: both;"></div>        
        </div>
</body>
</html>

contactme.php:

<?php

$EmailFrom = "email@gmail.com";
$EmailTo = "email@gmail.com";
$Subject = "contact form";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// informs user they submitted, redirects to homepage 
if ($success){
  alert("Thank you for your interest in our multiple sample processing system. A member of the Claremont Bio team will respond to you shortly.");
  window.location.assign(location.hostname);
}
else{    
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
  • 写回答

3条回答 默认 最新

  • douhoushou8385 2014-01-08 22:22
    关注
    alert("Thank you for your interest in our multiple sample processing system. A member of the Claremont Bio team will respond to you shortly.");
      window.location.assign(location.hostname);
    

    This is not valid php code, it is javascript. It definitely should not be in your php script.

    As an alternative, in your if($success) condition you could redirect to a "success.php" page. For example:

    if($success){
        header("Location: http://www.mydomain.com/success.php");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?