In PHP, You can display the image in HTML email template in two ways,

1. Your organization restricted your application directory by authorization and you cant able to access outside. In this case you can embed a images in html template
2. If there is no restriction and free to access anywhere you can display your image by using absolute and relative path directly

Please find the sample code for the first option:

<?php

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->From="m.achappan@gmail.com";
$mail->FromName="My site's mailer";
$mail->Sender="m.achappan@gmail.com";

$address = "achappan.mahalingam@yahoo.co.in";
$mail->AddAddress($address, "Achappan Mahalingam");

$mail->Subject = "HTML Email template logo test";

$mail->IsHTML(true);

$mail->AddEmbeddedImage('email_logo.png', 'logoimg', 'email_logo.png');
$mail->Body = "<p><img src=\"cid:logoimg\" /></p>";

$mail->AltBody = "Sample html logo Image test!";

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>

0 comments:

Blog Archive

Total Pageviews

Popular Posts