9951 explained code solutions for 126 technologies


phpmailerHow do I get the message ID of a sent email using PHPMailer?


To get the message ID of a sent email using PHPMailer, you can use the getLastMessageID() method. This method returns the message ID of the most recently sent email.

Example code

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

// your code to send email

echo $mail->getLastMessageID();

Output example

<[email protected]>

This code does the following:

  1. Includes the PHPMailerAutoload file.
  2. Instantiates a new PHPMailer object.
  3. Sends the email.
  4. Echoes the message ID of the most recently sent email.

Helpful links

Edit this code on GitHub