phpmailerHow do I add a logo to a PHPMailer message?
To add a logo to a PHPMailer message, you need to embed the logo image as an attachment and also reference it in the message body. Here is an example code block that demonstrates how to do this:
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Embed the logo image as an attachment
$mail->AddEmbeddedImage('/path/to/logo.jpg', 'logo_id', 'logo.jpg');
//Set the body of the message
$mail->Body = '<html><body>
<p>Here is an embedded logo: <img src="cid:logo_id" alt="Logo"/></p>
</body></html>';
//Send the message
$mail->Send();
This code will embed the logo image as an attachment and reference it in the message body using the cid
scheme. The AddEmbeddedImage
method takes three parameters; the first is the path to the image file, the second is an identifier that will be used to reference the image in the message body, and the third is the name of the image file.
Code explanation
$mail = new PHPMailer;
- Creates a new PHPMailer instance$mail->AddEmbeddedImage('/path/to/logo.jpg', 'logo_id', 'logo.jpg');
- Embeds the logo image as an attachment$mail->Body = '<html><body>...</body></html>';
- Sets the body of the message$mail->Send();
- Sends the message
For more information on using PHPMailer, please refer to the official documentation.
More of Phpmailer
- How can I configure PHPMailer to support Polish characters?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer to encode emails in UTF-8?
- How do I use PHPMailer to send a file?
- How do I use PHPMailer to send an HTML email with UTF-8 encoding?
- How can I send a UTF-8 encoded email using PHPMailer?
- How can I use PHPMailer in Yii 1?
- How do I check which version of PHPMailer I'm using?
- How do I use PHPMailer with Yii2?
See more codes...