$ .post到phpMailer失败了

时间:2016-08-11 08:51:27

标签: php jquery ajax phpmailer contact

我在我的js中使用$ .post检查我的表格,如果一切正常,数据将转到我的sendinquiry.php,它会发送联系表格电子邮件。所有工作只是因为我无法捕获“提交”到sdata的回声,以便我可以在jQuery中显示感谢信息。任何人吗?

的jQuery

.
.
.

if(errflag > 0){
        $('.disclaimer').addClass('errortext');
}

else {
        $.post(
            "sendinquiry.php",
            $('#contact_form').serialize(),
            function(sdata)
            {
                if(sdata == 'submitted') {
                    var ntext = '<div class="row topbot_m shortwidth"><div class="columns medium-12 text-center"><h3>THANK YOU FOR SUBMITTING YOUR ENQUIRY.</h3><p>Our Sales Representative will contact you shortly.</p></div></div>';
                    $('#contact_form').hide().html(ntext).fadeIn('slow');
                }
            }
            );   
  }

PHP

<?php


    $subject = "Line Enquiry Form";
    $gname = "High Line";
    $fname = $_POST['firstname'];
    $lname = $_POST['lastname'];
    $contactno = $_POST['contactno'];
    $emailadd = $_POST['emailadd'];
    $fmessage = $_POST['message'];

    require 'PHPMailermaster/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->SMTPDebug = 3;                               // Enable verbose debug output

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'xxx';                 // SMTP username
    $mail->Password = 'xxx';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    $mail->setFrom($emailadd, $fname);
    $mail->addAddress('sender@gmail.com', 'Reza San');     // Add a recipient
    $mail->addReplyTo($emailadd, $fname +' '+$lname);


    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = $subject;
    $mail->Body    ="<html>
                     <head>
                     <title>".$gname."</title>
                     </head>
                     <body>
                     <h2>".$subject."</h2>
                     <table>
                     <tr><td width='200'>First Name: </td><td>".$fname."</td></tr>
                     <tr><td width='200'>Last Name: </td><td>".$lname."</td></tr>
                     <tr><td width='200'>Contact No: </td><td>".$contactno."</td></tr>
                     <tr><td width='200'>Email Address: </td><td>".$emailadd."</td></tr>
                     <tr><td width='200'>Message: </td><td>".$fmessage."</td></tr>
                     </table>
                     </body>
                     </html>";
    if($mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'submitted';
    }

    ?>

0 个答案:

没有答案