PHPMailer 获取最后一条消息 ID 始终为空

问题描述 投票:0回答:0

我试图在 PHPMailer 发送电子邮件时获取最后一条消息 id。我的代码看起来像

$mail = new PHPMailer(true);

    try {

        $mail->SMTPDebug = 0;
        $mail->isSMTP();
        $mail->Host       = $s_server;
        $mail->SMTPAuth   = true;
        $mail->Username   = $s_username;
        $mail->Password   = $s_password;
        $mail->SMTPSecure = $s_protocol;
        $mail->Port       = $s_port;
        $mail->Hostname = $s_server;
        $mail->XMailer = ' ';
        
        $mail->SMTPOptions = array(
       'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        ); 
    
        //Recipients
        $mail->setFrom($s_from, $s_from_name);
        $mail->addAddress("[email protected]");
        
        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body    = $message;
        
        $mail->preSend();
        
        $mail->send();
        
        echo $mail->getLastMessageID();
        echo "<br>";
        echo "<pre>";
        print_r($mail);
        echo "</pre>";
        echo "<br>";
        echo $mail['FromName'];
        
        
    } 
    catch (Exception $e) {
        
    }

当我回显

$mail->getLastMessageID()
时,它总是空的,但是当我
var_dump($mail)
时,我有如下所示的数组。

PHPMailer\PHPMailer\PHPMailer Object
(
    [Priority] => 
    [CharSet] => iso-8859-1
    [ContentType] => text/html
    [Encoding] => 7bit
    [ErrorInfo] => 
    [From] => [email protected]
    [FromName] => Claire Smith
    [Sender] => [email protected]
    [Subject] => I am testing the SMTP
    [Body] => This is a test email!
    [AltBody] => 
    [Ical] => 
    [MIMEBody:protected] => This is a test email!

    [MIMEHeader:protected] => Date: Mon, 24 Jul 2023 23:51:46 -0400
To: [email protected]
From: Claire Smith 
Subject: I am testing the SMTP
Message-ID: 
MIME-Version: 1.0
Content-Type: text/html; charset=iso-8859-1

    [mailHeader:protected] => 
    [WordWrap] => 0
    [Mailer] => smtp
    [Sendmail] => /usr/sbin/sendmail
    [UseSendmailOptions] => 1
    [ConfirmReadingTo] => 
    [Hostname] => s1.example.com
    [MessageID] => 
    [MessageDate] => 
    [Host] => s1.example.com
    [Port] => 587
    [Helo] => 
    [SMTPSecure] => tls
    [SMTPAutoTLS] => 1
    [SMTPAuth] => 1
    [SMTPOptions] => Array
        (
            [ssl] => Array
                (
                    [verify_peer] => 
                    [verify_peer_name] => 
                    [allow_self_signed] => 1
                )

        )

    [Username] => [email protected]
    [Password] => ashgujkfhsjfgsfsfs
    [AuthType] => 
    [oauth:protected] => 
    [Timeout] => 300
    [dsn] => 
    [SMTPDebug] => 0
    [Debugoutput] => html
    [SMTPKeepAlive] => 
    [SingleTo] => 
    [SingleToArray:protected] => Array
        (
        )

    [do_verp] => 
    [AllowEmpty] => 
    [DKIM_selector] => 
    [DKIM_identity] => 
    [DKIM_passphrase] => 
    [DKIM_domain] => 
    [DKIM_copyHeaderFields] => 1
    [DKIM_extraHeaders] => Array
        (
        )

    [DKIM_private] => 
    [DKIM_private_string] => 
    [action_function] => 
    [XMailer] =>  
    [smtp:protected] => PHPMailer\PHPMailer\SMTP Object
        (
            [do_debug] => 0
            [Debugoutput] => html
            [do_verp] => 
            [Timeout] => 300
            [Timelimit] => 300
            [smtp_transaction_id_patterns:protected] => Array
                (
                    [exim] => /[\d]{3} OK id=(.*)/
                    [sendmail] => /[\d]{3} 2.0.0 (.*) Message/
                    [postfix] => /[\d]{3} 2.0.0 Ok: queued as (.*)/
                    [Microsoft_ESMTP] => /[0-9]{3} 2.[\d].0 (.*)@(?:.*) Queued mail for delivery/
                    [Amazon_SES] => /[\d]{3} Ok (.*)/
                    [SendGrid] => /[\d]{3} Ok: queued as (.*)/
                    [CampaignMonitor] => /[\d]{3} 2.0.0 OK:([a-zA-Z\d]{48})/
                    [Haraka] => /[\d]{3} Message Queued \((.*)\)/
                    [ZoneMTA] => /[\d]{3} Message queued as (.*)/
                    [Mailjet] => /[\d]{3} OK queued as (.*)/
                )

            [last_smtp_transaction_id:protected] => E17B83EE1B
            [smtp_conn:protected] => 
            [error:protected] => Array
                (
                    [error] => 
                    [detail] => 
                    [smtp_code] => 
                    [smtp_code_ex] => 
                )

            [helo_rply:protected] => 
            [server_caps:protected] => 
            [last_reply:protected] => 221 2.0.0 Bye

        )

    [to:protected] => Array
        (
            [0] => Array
                (
                    [0] => [email protected]
                    [1] => 
                )

        )

    [cc:protected] => Array
        (
        )

    [bcc:protected] => Array
        (
        )

    [ReplyTo:protected] => Array
        (
        )

    [all_recipients:protected] => Array
        (
            [[email protected]] => 1
        )

    [RecipientsQueue:protected] => Array
        (
        )

    [ReplyToQueue:protected] => Array
        (
        )

    [attachment:protected] => Array
        (
        )

    [CustomHeader:protected] => Array
        (
        )

    [lastMessageID:protected] => 
    [message_type:protected] => plain
    [boundary:protected] => Array
        (
            [1] => b1=_f8dsNdQvDQtBrLj5FRoswBhLHhU4CK838ZV8W1VqI
            [2] => b2=_f8dsNdQvDQtBrLj5FRoswBhLHhU4CK838ZV8W1VqI
            [3] => b3=_f8dsNdQvDQtBrLj5FRoswBhLHhU4CK838ZV8W1VqI
        )

    [language:protected] => Array
        (
        )

    [error_count:protected] => 0
    [sign_cert_file:protected] => 
    [sign_key_file:protected] => 
    [sign_extracerts_file:protected] => 
    [sign_key_pass:protected] => 
    [exceptions:protected] => 1
    [uniqueid:protected] => f8dsNdQvDQtBrLj5FRoswBhLHhU4CK838ZV8W1VqI
)

这里最后的uniqueid是我想要的消息id。但由于它是“受保护的对象”,我无法检索它。让我知道这里是否有人可以帮助我解决问题。谢谢!

php phpmailer
© www.soinside.com 2019 - 2024. All rights reserved.