0
//$mail->AddEmbeddedImage("data:image/jpeg;base64,'.base64_encode($cmpimage).'", "img","image/*");`
$mail->AddEmbeddedImage("GM Community Profile Image.jpg", "my-attach", "image/jpeg");`
//$mail->Body = '<img alt="hey" src="data:image/jpeg;base64,'.base64_encode($cmpimage).'">';
$mail->Body = '<img alt="PHPMailer" src="cid:my-attach">  ';

I need a way to send an email with an image in it(not attachments) and the image is taken from a form or a database.Im using phpmailer for mailing purposes.

I am new to php learning in trail and error fashion.Please help me find a solution. Thank you in advance.

1 Answers1

0

The first thing you need to do is to encode the image to base64. This will generate a long string which contains the encoded image Your encoded image will look something like this

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtAAAAEICAIAA...

This text(the encoded image) is what you save in your database. The recommend data type to use for this is BLOB (in MariaDb/MySql) or any other data type that can save long texts.

For example you could use an online converter like this one https://www.base64-image.de/ or use PHP built in functions. See Stackoverflow PHP answer: How to convert an image to base64 encoding?

Community
  • 1
  • 1
docliving
  • 111
  • 1
  • 6
  • I knew about base encode where i am able to display images from database on a website. However i am searching for a way to display images in a mail which is not working.Thanks for help anyways.@docliving – Venkat Narahari Apr 12 '17 at 02:33
  • I haven't confirmed it, but according to this post [http://stackoverflow.com/questions/16242489/send-a-base64-image-in-html-email, many email clients don't fully support attached images – docliving Apr 12 '17 at 18:28