2012-01-09 17 views
-1

私はうまく動作する連絡フォームを持っています。しかし、私はjQuery validation pluginを使用して送信前に空欄が残っていないことを確認しようとしていますが、プラグインを追加すると電子メールは受信されなくなります。次のようにjQueryの検証プラグインでPHPのメール機能が動作しない

コードは次のとおりです。

contact.html

$(document).ready(function(){ 
    $("form").validate({ 
    submitHandler: function() { 
     alert("Thank you for submitting your information."); 
     }, 
    }); 
}); 
<form class="cmxform" id="myform" method="post" action="contact.php"> 
    <fieldset> 
     <p><label for="cname">Name:</label> <input type="text" id="cname" name="name" maxlength="255" class="required" /></p> 
     <p><label for="cemail">Email:</label> <input type="text" id="cemail" name="email" maxlength="255" class="required email" /></p> 
     <p><label for="tel">Tel:</label> <input type="text" id="tel" name="tel" maxlength="15" class="required" /></p> 
     <p><label for="service">Service:</label> 
      <select name="service"> 
       <option value="option1">Option1</option> 
       <option value="option2">Option2</option> 
       <option value="option3">Option3</option> 
      </select> 
     </p> 
     <p><label for="comments">Comments:</label><textarea class="textarea" id="comments" name="comments" rows="7" cols="1"></textarea></p> 

     <input type="submit" name="submit" class="button" value="Submit" /> 
    </fieldset> 
</form> 

内側とcontact.php内

<?php 
if(isset($_POST['submit'])) 
{ 
$name = $_POST['name']; 
$email = $_POST['email']; 
$tel = $_POST['tel']; 
$service = $_POST['service']; 
$comments = $_POST['comments']; 

$header='From: '.$email."\r\n"; 
$header.='Content-Type: text/plain; charset=utf-8'; 

$msg='Message from: '.$name."\r\n"; 
$msg.='Email: '.$email."\r\n"; 
$msg.='Tel: '.$tel."\r\n"; 
$msg.='Interested in: '.$service."\r\n"; 
$msg.='Message: '.$comments."\r\n"; 
$msg.='Sent '.date("d/m/Y",time()); 
$msg.=utf8_decode(''); 

$to = '[email protected], [email protected], [email protected]'; 
$subject = 'Contact from website'; 

mail($to,$subject,$msg,$header); 
} 

header("Location: contact.html"); 
?> 

私はへのプラグインのために必要とされるどのような変更を知りませんPHPメール機能を使用します。私は誰かが見て、私がこれを理解するのを助けることができれば感謝します。前もって感謝します!

+2

あなたの 'submitHandler()'で[何か](http://docs.jquery.com/Plugins/Validation/validate#toptions)してはいけないのですか? – jprofitt

+0

jQueryとPHPはまったく無関係であるため、あなたは下落している可能性はかなり高いです。私はあなたのコンソールログをチェックして、エラーがあるかどうかを確認することから始めます。たとえ人間のエラーのように明白ではないとしても、何らかの方法でbtwが存在するからです(jprofittのコメントを参照)。それとは別に、実際のサイトのスクリプトタグの外に文書が用意されていないことを願っています。 –

+0

ありがとう、私はdownvoteについて疑問に思っていた:)私はあなたの提案の両方を検討します。そして、はい、jsの部分はドキュメントの頭のスクリプトタグの中にあります。私はここで本当に速く入力していました。 – brunn

答えて

0

確かにPHPは何もしませんでした。私はsubmitHandler関数にform.submit();がありませんでした。 jprofittとKai Qingに感謝します。

関連する問題