联系表单不适用于htaccess文件

时间:2016-02-23 13:24:49

标签: php .htaccess mod-rewrite contact-form

我只使用我的htaccess文件将 http://mywebsite.nl/test.php 更改为 http://mywebsite.nl/test

但现在我的联系表格不起作用。 (没有htaccess文件的情况下工作) 有人可以帮忙吗?

的.htaccess

RewriteEngine On

# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

的javascript

<script> 

$("#form").submit(function() {

var url = "contactengine.php"; 

$.ajax({
       type: "POST",
       url: url,
       data: $("#form").serialize(), 
       success: function(data)
       {
           $(".response").html(data); 
       }
     });

return false; 
$('#form')[0].reset();
});

</script>

contactengine.php

<?php
$EmailFrom = "contactform@website.nl";
$EmailTo = "info@website.nl";
$Subject = "subject text";
$Name = Trim(stripslashes($_POST['Name']));
$code = Trim(stripslashes($_POST['code']));  
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
$Bedrijf = Trim(stripslashes($_POST['Bedrijf']));

// 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 .= "\n";
$Body .= "Bedrijf: ";
$Body .= $Bedrijf;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "E-mail: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
if (filter_var($Email, FILTER_VALIDATE_EMAIL)) {

if ($code != "38b") {
    echo "Invalid code";
    } else {

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

// redirect to success page 
if ($success){
echo "Uw bericht is verzonden, we zullen zo spoedig mogelijk contact met u opnemen.";
}
else{
echo "<span>* Iets ging er mis, probeer het later nog eens. *</span>";
}
}
} else {
echo "Ongeldig e-mail adres";
}
?>

0 个答案:

没有答案