PHPMailer中奇怪的$ _POST行为

时间:2018-08-25 15:57:58

标签: php post phpmailer

我有一个奇怪的PHP问题。我正在将PHPMailer和JQuery一起使用以通过一些电子邮件地址进行发送并分别发送。

有效。但是... PHPMailer引发一个异常,即找不到发件人。我尝试了var_dump(),并在发件人电子邮件中回显了$ _POST或$ _GET,但我什么也没收到。其他$ _POST / $ _ GET可以很好地显示,只是电子邮件无法显示,即使在console.log中也是如此。

我提到它可行吗?那是不可思议的部分;脚本运行正常,并且电子邮件已发送。我刚得到一个PHPMailer异常,看不到$ _POST / $ _ GET变量。

任何帮助表示赞赏!

这是JQuery-

 // ------   Mail Send-Multi Button ------------ 

$(document).on('click','#send-multi',function(e){    
    e.preventDefault;
    var subj = $('#subject').val();
    var msg = $('#msg').val();

    var i = 0;

    $(".mailchek input:checkbox").each(function () {

        if (this.checked) {
            var sto = $(this).val();
            //alert($(this).val());
            i++;
            //alert(i);

            var itm = "sendto="+sto+"&subject="+subj+"&msg="+msg;
            alert(itm);
                    //ajax for multi email
                        $.ajax({ 
                            type: "GET", 
                            url: "webmail.php",  
                            data: itm, 
                            success: function(result){ 
                                //alert(result); 
                                alert("test");
                            },

                            error: function (xhr, ajaxOptions, thrownError) {
                             alert(xhr.status);
                             alert(thrownError);
                            }  

                          });//End AJAX             

       } //end Address loop

    });

这是PHPMailer-

   <?php


// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';


$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 0;                                 // Verbose debug off. Change to '2' for debug echo
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.somehost.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'info@somecompany.com';                 // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('info@somecompany.com', 'Name');
    $mail->addAddress($_GET[sendto]);     // Add a recipient


    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $_GET[subject];
    $mail->Body    = $_GET[msg];

    $mail->send();
    echo "here ".$send;
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

?>    

0 个答案:

没有答案