tags:

views:

531

answers:

3

Hi,

When I want to send email, my codes look like these:

$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: me@localhost' . "\r\n";

// Email Variables
$toUser  = 'you@something';
$subject = "Testing";
$body    = '<html><head><title></title></head><body>
            This is my picture <img src="http://domain.com/me.jpg"&gt;';

if(mail($toUser,$subject,$body,$headers)){
  echo "Email sent!!";
}

Here are my questions:

  1. Must I include the <html>, <head>, <title>... tags?
  2. Can I use stylesheet? For example, <div style="..."> ?
  3. I tested send the email to several accounts, if I include the <img> tag (for include image), it goes to junk mails, but if just plain text it goes to inbox. Anyone has any idea why it is? And how to solve it?
A: 
  1. No, some mail clients (especially webmail) will strip out anything before <body>
  2. You can use inline styles <div style=""> - using an external .css file is not recommended as it may not be loaded.
  3. If you only have a bit of text and an image it looks a lot like spam. If you had more text it may get treated differently.
Greg
+1  A: 

You should send your e-mail as multipart with a text/plain portion too.

That'll let people with text-only mail clients read it, and also count in your favour with any spam detection systems.

Alnitak
A: 

The problem with css in mail is that (again) is not standard in all mail services

here will find a complete descripction

http://www.campaignmonitor.com/css/