tags:

views:

106

answers:

4

hi,

can anyone tell me how can i send images as main body part in newsletter. how can i add any image from backend such that when i send a newsletter to the subscribers the image i want to show goes as main body part of the mail.

actually what i am saying is i have a form in which i can enter text and that text goes well in newsletter. now i want to add images in the form as well so that i don't need to write anything and only image will go in the mail as main body part of mail.

Thank you so much. you guys have been very supportive to me.

+2  A: 

You should create a multipart mime message, containing the image and maybe some HTML.

Sjoerd
how should i create that?
Rachel
Rachel, perhaps the tools available in your environment can make it easy. What you're trying to create will look like http://www.faqs.org/rfcs/rfc2049.html. (Look especially for the `image/jpeg` mime type annotation.)
sarnold
+6  A: 

If your newsletter is in HTML format, simply link to the live images that are on a server.

If you don't have your own server, simply host the images in any sort of free images hosting i.e. (imageshack.us) and on the body of your emails add:

<img src="http://imageshack.us/myimage.png"&gt;

And when the user opens the email, the images will load from the server.

As long as the email is multi-part (as previously suggested), any users that "can't read" HTML, will get the text version, which can have "hard-links" to the images on your live server.

Hope this helps you

Marcos Placona
This is an easy solution, but many e-mail clients do not by default open images which are not embedded in the e-mail.
Sjoerd
+4  A: 

First, you need to send your newsletter as HTML. Then, you can insert the image in your newsletter as

<img src="image_url">

The image_url can be remote or embedded. The remote image makes email smaller but most mail clients will ask user's approval. The embedded image will be displayed without asking user but it will be part of Email.

To use remote image, just host the image somewhere and put the URL as image_url.

Embedded image needs to be encoded as MIME parts. It's not trivial to do this. You need to use a package like PhpMailer,

http://sourceforge.net/projects/phpmailer/

Here is an example,

<?php
require("class.phpmailer-lite.php");
$mail = new PHPMailerLite();

$mail->From="[email protected]";
$mail->FromName="Your Name";

$mail->AddAddress("[email protected]");
$mail->Subject = "Your fancy newsletter";

$mail->IsHTML(true);
$mail->AddEmbeddedImage('image.png', 'image_id', 'test.png', 'base64', 'image/png');
$mail->Body = <<<EOT
<h1>My Newsletter</h1>
<p>This picture is embedded in newsletter: <img src="cid:image_id" /></p>
EOT;
$mail->AltBody="Text only, sorry no image";

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;
}
else
{
   echo "Mail is sent";
}
?>
ZZ Coder
A: 

I wouldn't recommend attaching images to an email....it's one of many flags to email service providers that you're sending spam. Best to do as listed in Marcos' solution and link from another server via absolute URL. Remember also to avoid the obvious email no-nos that will get you black flagged. It only takes one questionable email to raise a flag with a spam filter that will aggressively report you to the RBL's. And trust me, it's not fun to get off those lists!

My company sends tens of thousands of emails on behalf of our clients every day. We tried embedding at one point for a test, and found that more than 50% of our emails were either undeliverable or lost in the "great abyss" of spam filtering. By linking, we're at well over 85% deliverablility, depending of course on the quality of the emails provided.

bpeterson76