2010-01-25 2 views
0

Самое смешное, что это работало на один вечер. Я связался с моим хозяином, и они говорят, что нет причин, по которым он не должен работать. Я также попытался проверить его в Firebug, но он, казалось, отправлял. И я специально помещаю адрес электронной почты (размещенный в моем домене) в свой безопасный для электронной почты список, так что это тоже не преступник.Ajax/PHP контактная форма не в состоянии отправить письмо

Может кто-нибудь здесь взглянуть на него для меня? Я был бы так благодарен.

В заголовке у меня есть:

<script type="text/javascript"> 
    $(document).ready(function() { 
     var options = { 
      target: '#alert' 
     }; 
     $('#contactForm').ajaxForm(options); 
    }); 

    $.fn.clearForm = function() { 
     return this.each(function() { 
      var type = this.type, 
       tag = this.tagName.toLowerCase(); 
      if (tag == 'form') 
       return $(':input', this).clearForm(); 
      if (type == 'text' || type == 'password' || tag == 'textarea') 
       this.value = ''; 
      else if (type == 'checkbox' || type == 'radio') 
       this.checked = false; 
      else if (tag == 'select') 
       this.selectedIndex = -1; 
     }); 
    }; 
</script> 

Вот фактическая форма:

<form id="contactForm" method="post" action="sendmail.php"> 

<fieldset> 

<p>Email Me</p> 
<div id="fieldset_container"> 
<label for="name">Your Name:</label> 
<input type="text" name="name" id="name" /><br /><br /> 

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

<span style="display:none;"> 
<label for="last">Honeypot:</label> 
<input type="text" name="last" value="" id="last" /> 
</span><br /><br /> 

<label for="message">Comments &amp; Inquiries:</label> 
<textarea name="message" id="message" cols="" rows=""></textarea><br/> 
</div> 
<div id="submit_button"> 
<input type="submit" name="submit" id="submit" value="Send It" /> 
</div> 
</fieldset> 

</form> 

<div class="message"><div id="alert"></div></div> 

Вот код, с моей страницы валидация, sendmail.php:

<?php 

//  Who you want to recieve the emails from the form. (Hint: generally you.) 
$sendto = '[email protected]'; 

//  The subject you'll see in your inbox 
$subject = 'SH Contact Form'; 

//  Message for the user when he/she doesn't fill in the form correctly. 
$errormessage = 'There seems to have been a problem. May I suggest...'; 

//  Message for the user when he/she fills in the form correctly. 
$thanks = "Thanks for the email!"; 

//  Message for the bot when it fills in in at all. 
$honeypot = "You filled in the honeypot! If you're human, try again!"; 

//  Various messages displayed when the fields are empty. 
$emptyname = 'Entering your name?'; 
$emptyemail = 'Entering your email address?'; 
$emptymessage = 'Entering a message?'; 

//  Various messages displayed when the fields are incorrectly formatted. 
$alertname = 'Entering your name using only the standard alphabet?'; 
$alertemail = 'Entering your email in this format: <i>[email protected]</i>?'; 
$alertmessage = "Making sure you aren't using any parenthesis or other escaping     characters in the message? Most URLS are fine though!"; 


//Setting used variables. 
$alert = ''; 
$pass = 0; 

// Sanitizing the data, kind of done via error messages first. Twice is better! ;-) 
function clean_var($variable) { 
    $variable = strip_tags(stripslashes(trim(rtrim($variable)))); 
    return $variable; 
} 

//The first if for honeypot. 
if (empty($_REQUEST['last'])) { 

// A bunch of if's for all the fields and the error messages. 
if (empty($_REQUEST['name'])) { 
$pass = 1; 
$alert .= "<li>" . $emptyname . "</li>"; 
} elseif (ereg("[][{}()*+?.\\^$|]", $_REQUEST['name'])) { 
$pass = 1; 
$alert .= "<li>" . $alertname . "</li>"; 
} 
if (empty($_REQUEST['email'])) { 
$pass = 1; 
$alert .= "<li>" . $emptyemail . "</li>"; 
} elseif (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_REQUEST['email'])) { 
$pass = 1; 
$alert .= "<li>" . $alertemail . "</li>"; 
} 
if (empty($_REQUEST['message'])) { 
$pass = 1; 
$alert .= "<li>" . $emptymessage . "</li>"; 
} elseif (ereg("[][{}()*+?\\^$|]", $_REQUEST['message'])) { 
$pass = 1; 
$alert .= "<li>" . $alertmessage . "</li>"; 
} 

//If the user err'd, print the error messages. 
if ($pass==1) { 

    //This first line is for ajax/javascript, comment it or delete it if this isn't your cup o' tea. 
echo "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>"; 
echo "<b>" . $errormessage . "</b>"; 
echo "<ul>"; 
echo $alert; 
echo "</ul>"; 

// If the user didn't err and there is in fact a message, time to email it. 
} elseif (isset($_REQUEST['message'])) { 

    //Construct the message. 
    $message = "From: " . clean_var($_REQUEST['name']) . "\n"; 
    $message .= "Email: " . clean_var($_REQUEST['email']) . "\n"; 
    $message .= "Message: \n" . clean_var($_REQUEST['message']); 
    $header = 'From:'. clean_var($_REQUEST['email']); 

//Mail the message - for production 
    mail($sendto, $subject, $message, $header, "[email protected]"); 
//This is for javascript, 
    echo "<script>$(\".message\").hide(\"slow\").show(\"slow\").animate({opacity: 1.0}, 4000).hide(\"slow\"); $(':input').clearForm() </script>"; 
    echo $thanks; 
    die(); 

//Echo the email message - for development 
    echo "<br/><br/>" . $message; 

} 

//If honeypot is filled, trigger the message that bot likely won't see. 
} else { 
echo "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>"; 
echo $honeypot; 
} 
?> 
+0

О, боже. У меня закончилось кодирование или что-то (я здесь совершенно новый). Любой шанс, что кто-то здесь все еще может пропустить это для меня? – 2010-01-25 09:39:51

+1

Это вопрос программирования и будет двигаться в нужное место. Следуйте за ним, когда он движется. Но до тех пор исправлял форматирование для вашего последнего фрагмента, в котором отсутствовали отступы четырех пробелов для строк. Вам также может потребоваться прочитать следующее: http://meta.stackexchange.com/questions/2508/account-association-between-websites – random

ответ

1

Если сообщение эхом, то это не проблема с вашим javascript или html. Я бы предложил сделать свежий PHP файл с только 1 строку, которая пытается отправить почту:

mail('[email protected]', 'My Subject', 'This is a message'); 

жёстко все. Если это сработает, то вы знаете, что это, вероятно, не проблема с вашим хостом, и вам нужно проверить, что строка и переменные передаются в почту()

Смежные вопросы