duanmao2774 2018-08-25 15:57
浏览 45

PHPMailer中奇怪的$ _POST行为

I have a weird PHP issue. I'm using PHPMailer along with JQuery to itterate through a few email addresses and send them individually.

It works. BUT...PHPMailer raises an exception that sender is not found. I have tried var_dump(), and echoing the $_POST or $_GET for the sender email, and I get nothing. The other $_POST/$_GET show up just fine, just the email fails to show, even in the console.log.

Did I mention it works? That's the weird part; the script processes fine, and the emails are sent. I just get a PHPMailer exception and can't see the $_POST/$_GET variable.

Any help appreciated!

Here's is the 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

    });

Here is the 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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值