How to insert image in mail body when user click on send button. I am using php mail
-
1Can you paste in the code you have so far please? – Ant Mar 22 '11 at 11:12
-
Are you using the php `mail()` function? If so, I think that it is HTML mail, which I believe could use the `` tag. – Ryan Leonard Mar 22 '11 at 11:21
-
I will suggest you to go for phpmailer or swiftmailer for sending mails. – Shameer Mar 22 '11 at 11:51
-
Don't you normally want to send the mail instead of add an image when clicking a "send mail" button? – Steve-o Mar 22 '11 at 13:22
-
http://stackoverflow.com/questions/1606588/how-to-attach-and-show-image-in-mail-using-php – random Mar 22 '11 at 15:52
-
Does this answer your question? [base64 encoded images in email signatures](https://stackoverflow.com/questions/9110091/base64-encoded-images-in-email-signatures) – EdChum Mar 25 '20 at 07:30
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/

- 40,431
- 11
- 76
- 106

- 2,219
- 17
- 16
-
3I tried this, and it worked however. You need to add the absolute path. Like http://www.example.com/image.jpg And nog just image.jpg – user3806549 Nov 01 '16 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...

- 858
- 5
- 16
-
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](https://stackoverflow.com/a/4312865/924299). – showdev Mar 24 '20 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

- 1,213
- 2
- 12
- 20
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);

- 28,454
- 37
- 55
- 73

- 1,024
- 1
- 10
- 10