How to insert image in mail body when user click on send button. I am using php mail
4 Answers
To create an HTML email you can do something like this:
...
$message = "<html><head></head><body>";
$message .= "<img src='link-image.jpg' alt='' /></body></html>";
$headers = "From: $from_email";
$headers .= "Content-type: text/html";
mail($to, $subject, $message, $headers);
This should build an HTML email for you and you should then be able to insert just normal html.
edit You can read more about how to create HTML emails using PHP from here: http://css-tricks.com/sending-nice-html-email-with-php/
-
3I tried this, and it worked however. You need to add the absolute path. Like example.com/image.jpg And nog just image.jpg Nov 1, 2016 at 13:41
If you are actually asking: How to attach and insert inline images in a html email? you can use this for guidance :) https://www.quora.com/What-is-meant-by-inline-images-in-HTML
In that example, pay extra attention to how the src attribute of the img tag is filled (the "cid" is actually the id given as "Content-ID:" for the image attachment header).
Hope this helps, all the best...
-
I don't see any mention of "cid" or "Content-ID" on the linked page. For reference, see
Content-ID
@ How to embed images in email.– showdevMar 24, 2020 at 20:18
To insert image in body of mail, you can use phpmailerclass which links are
http://www.phpclasses.org/package/264-PHP-Full-featured-email-transfer-class-for-PHP.html
The correct is almost as the above marked answer. One most important part omitted is the absolute part of the image as indicated below:
$message = "<html><head></head><body>";
$message .= "<img src='http://example.com/images/link-image.jpg' alt='' /></body></html>";
$headers = "From: $from_email";
$headers .= "Content-type: text/html";
mail($to, $subject, $message, $headers);
mail()
function? If so, I think that it is HTML mail, which I believe could use the<a>
tag.