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!";
}
?>

Related Posts:

  • Difference between Div and Span tags in HTML? <span></span> as an in-line element and a <div></div> as a block level element. While a span allows you to separate things from the other elements around them on a page or within a document, it doe… Read More
  • What is Laravel? Laravel is a free, open source PHP web application framework, designed for the development of model–view–controller (MVC) web applications. Features: Laravel uses Composer as a dependency manager to add framework-agnost… Read More
  • SQL Injection SQL Injection is possible to alters the existing SQL commands to expose hidden data or to override the valuable ones, or even to execute dangerous system level commands on the database host. This is accomplished by the appli… Read More
  • Unsigned Integers in PHP PHP does not support unsigned Integers and Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX. … Read More
  • What happen If you convert NULL to String? When you convert NULL into String it will always return a empty value. … Read More

0 comments:

Blog Archive

Total Pageviews

15581

Popular Posts