Ilham Guezzoula
Ilham Guezzoula

Reputation: 145

How to send html email with images background without attaching via PHPMailer?

I am using phpmailer for sending emails, and I want to make a custom logo to be in top for my company ,the problem is the logo appear as attachment , Sow i want to know how to embed images in emails without attaching them? Thank you

$mail->Subject = 'Here is the subbject';
$mail->AddEmbeddedImage('logo.png', 'logo');
$mail->Body = '<html><body>';
$mail->Body = '<img src="cid:logo" style="width:100%"></img>';
$mail->Body = '<h3>Bonjour</h3>';
$mail->Body .='</body></html>';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

Upvotes: 1

Views: 1969

Answers (2)

MARTINS AKPALA K.
MARTINS AKPALA K.

Reputation: 1

$mail->AddEmbeddedImage('yourImage.png OR jpeg OR jpg','logo'); $mail->Body = "Hello Mr Martins, the image in this message is an embedded image .

";

Upvotes: 0

user5340092
user5340092

Reputation:

The body of the email must contain a direct link (not a relative link) to an image and that image should be a jpg. eg:

<?php
$body .= <<<EOD
<a href='https://my-website.com'><img src='https://my-website.com/image.jpg' alt='logo'></img></a>
EOD;
?>

Upvotes: 3

Related Questions