无法让这3个脚本很好地播放。试图让这个邮件功能正常工作并发送邮件。我删除了敏感信息并将其替换为通用术语。我还有另一个使用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();
});
});
});
答案 0 :(得分:0)
你并没有真正对ini_set函数做任何事情,你需要将有效的电子邮件和有效数据放入其中:
ini_set('SMTP' , 'smtp.yoursite.com');
ini_set('smtp_port' , '25');
ini_set('username' , 'example@example.com');
ini_set('password' , 'password');
ini_set('sendmail_from' , 'example@example.com');
此外,在设置这些设置之前发送电子邮件是没有意义的。
您实际上是在设置之前和之后两次发送邮件。定义设置,然后发送电子邮件。
顺便说一下,
this
won't
get a new line
除非使用可以处理此操作的包装器,否则必须在文本中添加\ n。