dole doug
dole doug

Reputation: 36048

php email() with image

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?

Upvotes: 2

Views: 290

Answers (5)

Adam Casey
Adam Casey

Reputation: 989

I have used HTML Mime Email extensively, and it is very straightforward:

http://www.phpclasses.org/browse/package/32.html

$mail = new htmlMimeMail();
$mailhtml = $mail->getFile('./emailheader.html');
$mailimglogo = $mail->getFile('./images/email-logo-1.jpg');
$mail->addHTMLImage($mailimglogo, 'email-logo-1.jpg', 'image/jpeg');
$mailhtml .= '<tr><td class="mailheader" colspan="2" align="center">';
$mailhtml .= '<img src="email-logo-1.jpg"></td></tr>';

...


$mailhtml .= $mail->getFile('./emailfooter.html');
$mail->setHtml($mailhtml);
$mail->setFrom('Dana Brainerd <[email protected]>');
$mail->setCc('[email protected]');
$mail->setBcc('[email protected]');
$mail->setSubject("Dana Brainerd Photography Order Number {$roworder['order_number']}");

$mailresult = $mail->send(array($roworder['customer_email']));                     

Upvotes: 2

sparkey0
sparkey0

Reputation: 1690

If you don't want to host the images someplace and would them to to be included inline, you'll need to do is encode them, insert the encoded text and reference them by ID. PHPmailer handles this pretty nicely (see Inline Attachments):

http://phpmailer.worxware.com/index.php?pg=tutorial#3

Otherwise, you can just reference them by their web address as described in the other posts.

Upvotes: 1

Sampson
Sampson

Reputation: 268344

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);

Upvotes: 3

Geert
Geert

Reputation: 1824

I would recommend Swift Mailer:

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

Upvotes: 4

silentcontributor
silentcontributor

Reputation: 85

If the emails are in html/mime format you could do it as html...

Upvotes: 2

Related Questions