2010-04-23 129 views
1

我使用的已经给我下面的PHP代码,它工作正常,除了自动回复位。我知道它不是很多代码,我只是不知道该怎么做,或者为什么它不工作。PHP表单自动响应

任何帮助,将不胜感激。提前致谢。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title> - Contact Us</title> 

<!-- css --> 
<link rel="stylesheet" type="text/css" href="css/reset.css" /> 
<link rel="stylesheet" type="text/css" href="css/styles.css" /> 
<link rel="stylesheet" type="text/css" href="css/colorbox.css" /> 

<!-- javascript libraries --> 
<?php require_once('includes/js.php'); ?> 

</head> 

<body> 
<?php 
//FIll out the settings below before using this script 
$your_email = "(email address)"; 
$website = "(website name)"; 
//BOTS TO BLOCK 
$bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer|T8Abot|Syntryx|WinHttp|WebBandit|nicebot)/i"; 
//Check if known bot is visiting 
if (preg_match($bots, $_SERVER["HTTP_USER_AGENT"])) { 
exit ("Sorry bots are not allowed here!"); 
} 

//Known Exploits 

$exploits = "/(content-type|bcc:|cc:|from:|reply-to:|javascript|onclick|onload)/i"; 

//Spam words 
$spam_words = "/(viagra|poker|blackjack|porn|sex)/i"; 

// BAD WORDS 
$words = "/(
bitch|dick|pussy|pussies|ass|fuck|cum|cumshot|cum shot| 
gangbang|gang bang|god dammit|goddammit|viagra|anus|analsex 
)/i"; 
//BAD WORD/SPAM WORD/EXPLOIT BLOCKER 
function wordBlock($word) { 
    //Make variables global 
global $words; 
global $exploits; 
global $spam_words; 

if (preg_match($words, $word)) { 
    $word = preg_replace($words, "#####", $word); 
} 
if(preg_match($exploits,$word)){ 
$word = preg_replace($exploits,"",$word); 

} 
if(preg_match($spam_words,$word)){ 
    $word = preg_replace($spam_words,"$$$$",$word); 
} 
return $word; 
} 
//CLean data function 
function dataClean($data) { 
$data = stripslashes(trim(rawurldecode(strip_tags($data)))); 
return $data; 
} 
//CREATE MAIN VARIABLES 
$name = (isset ($_POST['name'])) ? dataClean($_POST['name']) : FALSE; 
$company = (isset ($_POST['company'])) ? dataClean($_POST['company']) : FALSE; 
$address = (isset ($_POST['address'])) ? dataClean($_POST['address']) : FALSE; 
$postcode = (isset ($_POST['postcode'])) ? dataClean($_POST['postcode']) : FALSE; 
$phone = (isset ($_POST['phone'])) ? dataClean($_POST['phone']) : FALSE; 
$email = (isset ($_POST['email'])) ? dataClean($_POST['email']) : FALSE; 
$comment = (isset ($_POST['message'])) ? wordBlock(dataClean($_POST['message'])) : FALSE; 
$submit = (isset ($_POST['send'])) ? TRUE : FALSE; 
$email_check = "/^[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,6}$/i"; 
//$ip = $_SERVER["REMOTE_ADDR"]; 
$errors = array(); 
//Check if send button was clicked 
if ($submit) { 
if (!$name) { 
    $errors[] = "Please enter a name!"; 
} 
if ($name) { 
    if (!ereg("^[A-Za-z' -]*$", $name)) { 
    $errors[] = "You may not use special characters in the name field!"; 
    } 
} 
if (!$email) { 
    $errors[] = "Please enter an email address!"; 
} 
if ($email) { 
    if (!preg_match($email_check, $email)) { 
    $errors[] = "The E-mail you entered is invalid!"; 
    } 
} 
/* 
if (!$subject) { 
    $errors[] = "Please enter an email subject!"; 
} 
*/ 
if (!$comment) { 
    $errors[] = "Please don't leave the message field blank!"; 
} 
//Check if any errors are present 
if (count($errors) > 0) { 
    foreach ($errors AS $error) { 
    print "&bull; $error <br />"; 
    } 
} 
else { 
//MESSAGE TO SEND TO ADMIN 
//Create main headers 
    $headers = "From: " . $website . " <$your_email> \n"; 
    $headers .= "Reply-to:" . $email . " \n"; 
    $headers .= "MIME-Version: 1.0\n"; 
    $headers .= "Content-Transfer-Encoding: 8bit\n"; 
    $headers .= "Content-Type: text/html; charset=UTF-8\n"; 
    $message = ""; 
    $message .= "<h1>New E-Mail From " . $website . "</h1><br /><br />"; 
    $message .= "<b>Name:</b> " . $name . "<br />"; 
    $message .= "<b>Company:</b> " . $company . "<br />"; 
    $message .= "<b>Address:</b> " . $address . "<br />"; 
    $message .= "<b>Postcode:</b > " . $postcode . "<br />"; 
    $message .= "<b>Phone No:</b> " . $phone . "<br />"; 
    $message .= "<b>E-mail:</b> " . $email . "<br />"; 
    $message .= "<b>Message:</b> " . $comment . "<br />"; 
//E-mails subject 
    $mail_subject = "Message from " . $website . ""; 
/* 
CHECK TO BE SURE FIRST E-MAIL TO ADMIN IS A SUCCESS AND SEND EMAIL TO ADMIN 
OTHERWISE DON'T SEND AUTO RESPONCE 
*/ 
    if (mail($your_email, $mail_subject, $message, $headers)) { 
//UNSET ALL VARIABLES 
    unset ($name, $email, $company, $address, $postcode, $phone, $comment, $_REQUEST); 
//JAVASCRIPT SUCCESS MESSAGE 
    echo " 
    <script type='text/javascript' language='JavaScript'> 
    alert('Your message has been sent'); 
    </script> 
    "; 
//SUCCESS MESSAGE TO SHOW IF JAVASCRIPT IS DISABLED 
    echo "<noscript><p>THANK YOU YOUR MESSAGE HAS BEEN SENT</p></noscript>"; 
/* 
-----------------END MAIL BLOCK FOR SENDING TO ADMIN AND START AUTO RESPONCE SEND----------------- 
*/ 
//AUTO RESPONCE MESSAGE 
//Create main headers 
    $headers = "From: " . $website . " <$your_email> \n"; 
    $headers .= "Reply-to:" . $your_email . " \n"; 
    $headers .= "MIME-Version: 1.0\n"; 
    $headers .= "Content-Transfer-Encoding: 8bit\n"; 
    $headers .= "Content-Type: text/html; charset=UTF-8\n"; 
    $message = ""; 
    $message .= "<h1>Thank You For Contacting Us </h1><br /><br />"; 
    $message .= "On behalf of <b>" . $website . "</b> we wanna thank you for contacting us and to let you know we will respond to your message as soon as possible thank you again."; 
//E-mails subject 
    $mail_subject = "Thank you for contacting " . $website . ""; 
//Send the email 
    mail($email, $mail_subject, $message, $headers); 
/* 
-----------------END MAIL BLOCK FOR SENDING AUTO RESPONCE ----------------- 
*/ 
    } 
    else { 
    echo " 
    <script type='text/javascript' language='JavaScript'> 
    alert('Sorry could not send your message'); 
    </script> 
    "; 
    echo "<noscript><p style='color:red;'>SORRY COULD NOT SEND YOUR MESSAGE</p></noscript>"; 
    } 
} 
} 
?> 


<div id="wrapper"> 
<div id="grad_overlay"> 

     <!-- Header --> 

     <div id="header">   
      <a href="index.php" title="Regal Balustrades"><img src="images/regal_logo.png" alt="Regal Balustrades" /></a> 
      <div id="strapline">   
       <img src="images/strapline.png" alt="Architectural metalwork systems" /> 
      </div> 
     </div> 

     <!-- Navigation --> 

     <div id="nav"> 
    <?php require_once('includes/nav.php'); ?> 
     </div> 

     <!-- Content --> 

     <div id="content"> 
     <div id="details"> 
       <p class="getintouch env">Get In Touch</p> 
       <ul class="details"> 
        <li>T. (0117) 935 3888</li> 
        <li>F. (0117) 967 7333</li> 
        <li>E. <a href="mailto:[email protected]" title="Contact via email">[email protected]</a></li> 
       </ul> 

       <p class="whereto hse">Where To Find Us</p> 
       <ul class="details"> 
        <li>Regal Balustrades</li> 
        <li>Regal House, </li> 
        <li>Honey Hill Road,</li> 
        <li>Kingswood, </li> 
        <li>Bristol BS15 4HG</li> 
       </ul> 

      </div> 

      <div id="contact"> 
       <h1>Contact us</h1> 
       <p>Please use this form to request further information about Regal Balustrades and our services. To speak to a member of our staff in person, please call us on 0117 9353888</p> 
       <div id="form"> 

<form method='POST' action='<?php echo "".$_SERVER['PHP_SELF'].""; ?>'> 

<p class='form-element'> 
    <label for='name'>Name:</label> 
    <input type='text' name='name' value='<?php echo "" . $_REQUEST['name'] . "";?>' /> 
</p> 

<p class='form-element'> 
    <label for='company'>Company:</label> 
    <input type='text' name='company' value='<?php echo "" . $_REQUEST['company'] . "";?>' /> 
</p> 

<p class='form-element'> 
    <label for='address'>Address:</label> 
    <textarea name='address' rows='5' id='address' class='address' ><?php echo "" . $_REQUEST['address'] . "";?></textarea> 
</p> 

<p class='form-element'> 
    <label for='postcode'>Postcode:</label> 
    <input type='text' name='postcode' value='<?php echo "" . $_REQUEST['postcode'] . "";?>' /> 
</p> 

<p class='form-element'> 
    <label for='phone'>Telephone:</label> 
    <input type='text' name='phone' value='<?php echo "" . $_REQUEST['phone'] . "";?>' /> 
</p> 

<p class='form-element'> 
    <label for='email'>Email:</label> 
    <input type='text' name='email' value='<?php echo "" . $_REQUEST['email'] . "";?>' /> 
</p> 

</div> 

<div id='form-right'> 

<p class='form-element'> 
    <label for='message'>Enquiry:</label> 
    <textarea name='message' class='enquiry' id='enquiry' rows='5' cols='40' ><?php echo "" . $_REQUEST['message'] . "";?></textarea> 
</p> 

<p class='form-element'> 
<input type='submit' class='submit' name='send' value='Send message' /> 
</p> 

</div> 
<p class='nb'><em>We will respond as soon as possible.</em></p> 

</form> 



       </div> 



      </div> 


     </div>   

</div> 
</div> 



<!-- Footer --> 

<div id="footer-container"> 
<?php require_once('includes/footer.php'); ?> 
</div> 

<!-- js functions --> 
<script> 
$(document).ready(function() { 
$("ul#navig li:nth-child(6)").addClass("navon"); 
}); 
</script> 


</body> 
</html> 
+0

究竟是不是工作?你遇到了什么错误? – 2010-04-23 18:28:18

+5

我得到了一个坏词正则表达式的踢出。 – webbiedave 2010-04-23 18:44:08

+0

奥伦,嗨,我没有得到一个错误我只是没有收到自动回复邮件时,我对它进行测试。我也一直在现场服务器上进行测试。 – Mark 2010-04-24 08:16:41

回答

-1

尝试$words摆脱换行类似如下:

// BAD WORDS 
$words = "/(word|word|word|"; 
$words .= "word|word|word)/i"; 

或者

// BAD WORDS 
$words = "/(word|word|word|word|word|word)/i"; 
+0

有没有\ n或\ r或\ r \ n或\ n \ r或无论在那里,因此也可以在原来的版本不换行。只要将字符串分割为两个赋值并将其连接起来就不会添加换行符,除非您自己添加它们。 – 2010-04-23 19:37:34

+0

Aww crud ...抱歉关于downvote。下次我需要更仔细地阅读。如果你可以编辑你的答案,我会重新投票。 – 2010-04-23 19:46:58

0

这很可能是你的邮件服务器出现问题。你确定你可以通过mail()函数发送邮件吗?为了找到答案,只包含下面的代码在服务器上运行一个小的脚本:

<?php 
mail('[email protected]', 'Test mail', 'If you receive this message, everything works fine'); 
?> 

如果你没有得到的测试消息(你必须在脚本中的地址改为自己的地址),有可能成为邮件服务器的问题。您可以安装一个邮件服务器或看看以下问题来改变你的代码,这样就可以通过外部服务器发送邮件:PHP - mail() function not working on my hosting