-1
我有一個聯繫表單,工作正常。不過,我正在嘗試使用jQuery validation plugin來檢查提交前是否還有空的字段,但是當我添加插件時,我不再收到任何電子郵件。PHP的郵件功能不適用於jQuery驗證插件
的代碼如下:
內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郵件功能。我很感激,如果有人可以看看,並幫我弄清楚這一點。提前致謝!
你不應該在'submitHandler()'中做[something](http://docs.jquery.com/Plugins/Validation/validate#toptions)嗎? – jprofitt 2012-01-09 20:49:53
由於jQuery和PHP是完全無關的,所以很有可能會陷入低谷。我會先檢查一下你的控制檯日誌,看看是否有錯誤 - 哪個btw會以某種方式出現,即使它不明顯......就像人爲錯誤(請參閱jprofitt的評論)。除此之外,我當然希望你真的沒有在你的實際站點上的腳本標記之外準備好你的文檔。 – 2012-01-09 20:51:03
謝謝,我想知道downvote :)我會考慮你的兩個建議。是的,js部分位於文檔頭部的腳本標籤內部,我在這裏輸入的速度非常快。 – brunn 2012-01-09 21:04:13