我有 2 段代码,我无法通过电子邮件表单发送邮件。我想我错过了我的 sendmail.php 文件。谁能帮我写这个或使用脚本来使用它?我拥有的代码是。
var name = jQuery("input#name").val();
if (name == "") {
jQuery("span#name_error").show();
jQuery("input#name").focus();
return false;
}
var email = jQuery("input#email").val();
if (email == "") {
jQuery("span#email_error").show();
jQuery("input#email").focus();
return false;
}
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test(email)) {
jQuery("span#email_error2").show();
jQuery("input#email").focus();
return false;
}
var subject = jQuery("input#subject").val();
var msg = jQuery("textarea#msg").val();
if (msg == "") {
jQuery("span#msg_error").show();
jQuery("textarea#msg").focus();
return false;
}
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
//alert (dataString);return false;
jQuery.ajax({
type: "POST",
url: "sendemail.php",
data: dataString,
success: function() {
jQuery('#contactform').html("<div id='message'></div>");
jQuery('#message').html("<strong>Contact Form Submitted!</strong>")
.append("<p>We will be in touch soon.</p>")
.hide()
.fadeIn(1500, function() {
jQuery('#message');
});
}
});
return false;
});
});'
和
<div id="contactform">
<form id="contact" action="#">
<fieldset>
<span class="error" id="name_error">Please enter name !</span>
<span class="error" id="email_error">Please enter email address !</span>
<span class="error" id="email_error2">Please enter valid email address !</span>
<span class="error" id="msg_error">Please enter message !</span>
<label for="name" id="name_label">Your Name (required)</label>
<input type="text" name="name" id="name" size="50" value="" class="text-input" />
<label for="email" id="email_label">Your Email (required)</label>
<input type="text" name="email" id="email" size="50" value="" class="text-input" />
<label for="subject" id="subject_label">Subject</label>
<input type="text" name="subject" id="subject" size="50" value="" class="text-input" />
<label for="msg" id="msg_label">Your Message (required)</label>
<textarea rows="8" name="msg" id="msg" class="text-input"></textarea>
<br />
<input type="submit" name="submit" class="button" id="submit_btn" value="Send"/>
</fieldset>
</form>
</div><!-- end contactform -->
请帮忙。