Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using PHP Mailer to Send HTML Emails with Images
$mail = new PHPMailer();$mail = new PHPMailer();
$mail->Host = ";";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';
$mail->FromName="My site's mailer";
$mail->AddReplyTo("", "Replies for my site");
$mail->Subject = "Test 1";
$mail->AddEmbeddedImage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg
$mail->Body = "<h1>Test 1 of PHPMailer html</h1>
<p>This is a test picture: <img src=\"cid:logoimg\" /></p>";
$mail->AltBody="This is text only alternative body.";
echo "Error sending: " . $mail->ErrorInfo;;
echo "Letter is sent";
Copy link

guztartas commented Apr 22, 2019

Very good!
Thanks for all.

Copy link

bozdoz commented May 8, 2020

Couldn't get the official docs examples to work, but this works great (minus AddEmbeddedImage -> addEmbeddedImage).


Copy link

sebesh commented Mar 2, 2021


Copy link

divSyntax commented Mar 8, 2022

OMG!! Thx!! Worked for me! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment