Php 通过ajax将表单值发送到smtp邮件表单

Php 通过ajax将表单值发送到smtp邮件表单,php,jquery,ajax,smtp,sendmail,Php,Jquery,Ajax,Smtp,Sendmail,电子邮件表单未发送,无法找出原因。我使用了这篇帖子的建议表单来创建表单 这样做的原因是为了使IE8和IE9友好的表单变得更好 点击功能 $("form#example-advanced-form").click(function() { //alert("submitting?"); // validate() just checks that required fields have

电子邮件表单未发送,无法找出原因。我使用了这篇帖子的建议表单来创建表单

这样做的原因是为了使IE8和IE9友好的表单变得更好

点击功能

                $("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

是否完成了任何基本调试,如检查
->Send()调用的返回值?您所有的代码都只是假设任何东西都不会失败,这是一个非常坏的习惯。如何返回send的值,恐怕我对这方面的知识还处于初级阶段?
$result=$mail->send();如果($result==false){die($mail->ErrorInfo);}
我应该把它放在哪个文件中?你能告诉我如何通过ajax对这两个字段进行pas吗?目前看起来是这样的,但由于它们是文本区域和单选按钮,我认为语法错误,因此它不起作用$(“#coverletter').val(),//文本区域$(“#workfor').val()//单选按钮”
    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();
    }
            http_redirect("http://www.this.com");