How to use PHPMailer to Send HTML Emails With Images

Q

Useful PHP Code Snippets for Developers - Using PHPMailer To Send HTML Emails With Images

✍: Guest

A

IsSMTP();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';
 
$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";
$mail->Sender="mailer@example.com";
$mail->AddReplyTo("replies@example.com", "Replies for my site");
 
$mail->AddAddress("email@example.com");
$mail->Subject = "Test 1";
 
$mail->IsHTML(true);
$mail->AddEmbeddedImage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg
$mail->Body = "

Test 1 of PHPMailer html

This is a test picture:

"; $mail->AltBody="This is text only alternative body."; if(!$mail->Send()) { echo "Error sending: " . $mail->ErrorInfo;; } else { echo "Letter is sent"; } ?>

2015-06-19, 1530🔥, 0💬