Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php email() with image

Tags:

php

email

Using outlook I can send emails with images inserted into message body(not as attachment). How can i do that using mail() function from PHP?

like image 210
dole doug Avatar asked May 15 '26 13:05

dole doug


2 Answers

I would recommend Swift Mailer:

http://swiftmailer.org/docs/embedding-files

like image 104
Geert Avatar answered May 19 '26 00:05

Geert


From the documentation (Example #4 Sending HTML email):

Note the $message variables contents, and the value of the $headers variable.

$to       = "[email protected]";
$subject  = "HTML Email";
$message  = "Hello <img src='http://mysite.com/world.jpg' />";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: HTML Emailer <[email protected]>' . "\r\n";

mail($to, $subject, $message, $headers);
like image 43
Sampson Avatar answered May 19 '26 00:05

Sampson