PHPMailer Получить идентификатор последнего сообщения всегда пустоPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 PHPMailer Получить идентификатор последнего сообщения всегда пусто

Сообщение Anonymous »

Я пытаюсь получить идентификатор последнего сообщения от PHPMailer при отправке электронного письма. Мой код выглядит так:

Код: Выделить всё

$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("mygmail@gmail.com");

$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body    = $message;

$mail->preSend();

$mail->send();

echo $mail->getLastMessageID();
echo "
";
echo "
";
print_r($mail);
echo "";
echo "
";
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] => user@example.com
[FromName] => Claire Smith
[Sender] => user@example.com
[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: mygmail@gmail.com
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] => user@example.com
[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] => mygmail@gmail.com
[1] =>
)

)

[cc:protected] => Array
(
)

[bcc:protected] => Array
(
)

[ReplyTo:protected] => Array
(
)

[all_recipients:protected] => Array
(
[mygmail@gmail.com] => 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 – это идентификатор сообщения, которое мне нужно. Но поскольку это защищенный объект, я не могу его получить. Дайте мне знать, если кто-нибудь здесь может помочь мне решить эту проблему. Спасибо!

Подробнее здесь: https://stackoverflow.com/questions/767 ... ways-empty
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»