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
:
<?php
// Include PHPMailer library
require_once('PHPMailer/PHPMailerAutoload.php');
// 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 toMyXMailer
.
Helpful links
More of Phpmailer
- How do I configure PHPmailer to use Zoho SMTP?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to support Polish characters?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer with Yii2?
- How can I use PHPMailer without SMTP secure?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I determine which version of PHPMailer I'm using?
- How can I send a UTF-8 encoded email using PHPMailer?
See more codes...