IT BS Help

How to send embed images into html email using php

in Coding

First you need to use PHP Mailer and not use the builtin php send mail function ( Direct Download PHPMailer-master or https://github.com/PHPMailer/PHPMailer  )

Now you can create a php file with content below…

 

<?php
require_once(‘PHPMailerAutoload.php’);

//The true param means it will throw exceptions on errors, which we need to catch
$mail = new PHPMailer(true);
//Telling the class to use SMTP
$mail->IsSMTP();

try {
$mail->Host = “192.168.1.5”; // SMTP server
$mail->Port = 25; // set the SMTP port
$mail->IsHTML(true);
$mail->SetFrom(‘[email protected]’, ‘from name’);
$mail->AddAddress(‘[email protected]’, ‘to name’);
$mail->Subject = ‘test with embed image’;

$mail->AddEmbeddedImage(“yourimage.PNG”, “my-attach”, “yourimage.PNG”);

$mail->Body = ‘Your <b>HTML Email Test</b> with an embedded Image: <br /><br /><img src=”cid:my-attach”> <br /> Here is an image!’;

//$mail->AddAttachment(‘yourimage.png’); // this is a regular attachment (Not inline)
$mail->Send();

echo “Message Sent OK<p></p>\n”;
} catch (phpmailerException $e) {
echo $e->errorMessage(); //error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //error messages from anything else!
}
?>

0