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  )

Now you can create a php file with content below…



//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

try {
$mail->Host = “”; // SMTP server
$mail->Port = 25; // set the SMTP port
$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)

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!