tags:

views:

64

answers:

5

Hi there

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?

+2  A: 

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

mr1989foster
+4  A: 

I would recommend Swift Mailer:

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

Geert
+3  A: 

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);
Jonathan Sampson
+1  A: 

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.

sparkey0
+1  A: 

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']));
Adam Casey