無法讓這3個腳本很好地播放。試圖讓這個郵件功能工作併發送郵件。我刪除了敏感信息並將其替換爲通用術語。我也ahve另一個PHP郵件功能,使用preg_match和其他驗證方法,但它不工作,所以我決定刪除,直到它的工作,然後嘗試再次添加驗證服務器端..PHP郵件功能無法正常工作..客戶端驗證
我不是那麼好在PHP,但我決心繞我的頭,所以任何幫助將不勝感激。
我通常測試所有這些在我的wamp上,但有一個活的開發服務器@ marinetechegypt.com/contact.php/它可能不是最新的壽。
以下是所有相關文件的內容。
HTML形式(contact.php)
<div class="col one-half">
<h3> Send us an Email </h3>
<div class="ajax_message"></div>
<form class="contact-form" method="post" action="php-mailer.php">
<input type="hidden" name="ac" value="login" />
<p>
<label for="fname"> Your Name <span class="required"> * </span> </label>
<input type="text" name="fname" class="input-short" id="fname" placeholder="Your Full Name" />
<?php if(isset($errName1)) echo $errName1; ?>
</p>
<p>
<label for="email"> Your Email <span class="required"> * </span> </label>
<input type="text" name="email" class="input-long" id="email" placeholder="Your Email" />
<?php if(isset($errEmail)) echo $errEmail; ?>
</p>
<p>
<label> Subject </label>
<input name="subject" type="text" id="subject" class="input-short" placeholder="Subject"/>
</p>
<p>
<label for="message"> Your Message <span class="required"> * </span> </label>
<textarea name="message" class="textarea-message" id="textarea" placeholder="Your Message"></textarea>
<?php if(isset($errMessage)) echo $errMessage; ?>
</p>
<p><input name="submit" type="submit" value="Send Message" class="button small grey contact-submit" /></p>
</form>
<div class="error-container" style="display:none;"> Please fill the above required fields correctly! </div>
</div>
PHP-mailer.php文件:
<?php
if(isset($_POST['submit'])) {
$to = "RecipientEmailInbox";
$subject = $_POST['subject'];
$first_name_field = $_POST['fname'];
$email_field = $_POST['email'];
$message = $_POST['textarea'];
$message = "
Name: $first_name_field
Email: $email_field
Message: $message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: <RecipientEmailInbox>' . "\r\n";
$headers .= '[From] <SenderEmailInbox>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
include("OnCompleteURL");
ini_set("sendmail_from","EmailHeaderFrom");
ini_set("SMTP","SMTPAddress");
mail($to, $subject, $message, $headers);
} else {
echo "Error phpmailer";
}
?>
JS客戶端驗證
$(document).ready(function(){
$.validator.addMethod("notEqual", function(value, element, param) {
return this.optional(element) || value != param;
}, "Please choose a value!");
$(".contact-form").each(function(){
$container = $(this).next("div.error-container");
//Validate Starts
$(this).validate({
onfocusout: function(element) { $(element).valid(); },
errorContainer: $container,
rules:{
fname:{required:true,minlength:3,notEqual:'Your Full Name'},
email:{required:true,email:true,notEqual:'Your Email'},
subject:{notEqual:'Subject'},
message:{notEqual:'Your Message'}
,message:{required:true,minlength:10}
}
});//Validate End
//Submit Starts
$(this).submit(function(e){
$frm = $(this);
$name = $frm.find('*[name=fname]').val();
$email = $frm.find('*[name=email]').val();
$subject = $frm.find('*[name=subject]').val();
$message = $frm.find('*[name=message]').val();
if($frm.find('*[name=fname]').is('.valid') && $frm.find('*[name=email]').is('.valid')) {
var action = $frm.attr('action');
$frm.find('*[name=submit]').attr('disabled', 'disabled').after('');
$frm.prev(".ajax_message").slideUp(750, function() {
$ajax_container = $(this);
$ajax_container.hide();
$.post(action, {
name: $name,
email: $email,
subject: $subject,
message: $message
}, function (data) {
$ajax_container.html(data);
$ajax_container.slideDown('slow');
$frm.find('*[name=submit]').attr('disabled', '');
if (data.match('success') != null) $frm.slideUp('slow');
});
});
}
e.preventDefault();
});
});
});
問題是什麼?什麼不工作? –
如果您正在使用WAMP進行測試,那麼郵件功能可能無法正常工作,因爲您可能沒有在本地設置郵件服務器。你在哪裏測試這個? – AgilE
你有什麼錯誤嗎? –