电子邮件表单不发送,无法找出原因。我用这个帖子的建议表单来创建表单。 Submit form and a textarea on ajax post
这样做的原因是为了使IE8和9友好的形式更有效。
点击功能....
$("form#example-advanced-form").click(function() {
//alert("submitting?");
// validate() just checks that required fields have values
//if (validate()) {
$.ajax({
type: 'POST',
url: 'PHPMailer/sendMyform.php',
data: { name: $('#name').val(),
from: $('#email').val(),
subject: $('#role').val(),
message: $('#coverletter').val()
},// end data
success: function clearFields() {
$('#name').val('');
$('#email').val('');
} // end success
}); // end ajax
/*}
else
{
var errmsg = "Your email could not be sent.<br />";
errmsg += "Please ensure that you've filled in all the fields.";
$(".errmsg").html(errmsg);
$(".errmsg").css("color", "#ff0000");
}*/
$('form#example-advanced-form').submit();
}); // end click
接收数据的发送邮件表单......
error_reporting(E_ALL);
require_once("class.phpmailer.php");
include("class.smtp.php");
$email = new PHPMailer();
try
{
//
// Set server details for send
//
$email->IsSMTP();
$email->Host = "****";
$email->Port = 25;
$email->SMTPAuth = true;
$email->Username = "****";
$email->Password = "****";
//
// Send mail from the contact form
//
$to = "****";
$from = $_POST["email"];
$name = $_POST["name"];
$subject = "From web: ".$_POST["role"];
$message = $_POST["name"];
$body = "<p>Hi,</p>";
$body .= "<p>You have received a new query on your website.</p><p>Please see below:</p>";
$body .= "<p>";
$body .= str_replace("\r\n", "<br />", $message);
$body .= "</p>";
$body .= "</body></html>";
$email->SetFrom($from, $name);
$email->AddReplyTo($from, $name);
$email->AddAddress($to, $to);
$email->Subject = $subject;
$email->Body = $body;
$email->IsHTML(true);
$email->Send();
session_start();
$_SESSION["mailresult"] = "success";
http_redirect("http://www.this.com");
}
catch (Exception $e)
{
$_SESSION["mailresult"] = "failed";
$_SESSION["mailerror"] = $e->getMessage();
}
我收到错误在第49行调用未定义的函数,这是......
http_redirect("http://www.this.com");