9951 explained code solutions for 126 technologies

phpmailerHow do I set the X-Mailer header using PHPMailer?

The X-Mailer header can be set using PHPMailer by using the addCustomHeader() method. The following example code block sets the X-Mailer header to MyXMailer:

// Include PHPMailer library

// Create new PHPMailer instance
$mail = new PHPMailer;

// Set X-Mailer header
$mail->addCustomHeader('X-Mailer', 'MyXMailer');

// ...


The addCustomHeader() method takes two parameters: the header name and header value. The header name is the name of the header, in this case X-Mailer, and the header value is the value of the header, in this case MyXMailer.

The following list explains the parts of the code example:

  • require_once('PHPMailer/PHPMailerAutoload.php');: This line includes the PHPMailer library.
  • $mail = new PHPMailer;: This line creates a new PHPMailer instance.
  • $mail->addCustomHeader('X-Mailer', 'MyXMailer');: This line sets the X-Mailer header to MyXMailer.

Helpful links

Edit this code on GitHub