What to include in email headers using php mail ()?

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

$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">';

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

      

Here are my questions:

  • Should I include tags <html>, <head>, <title>...

    ?
  • Can a stylesheet be used? For example <div style="...">

    ,?
  • I tested sending an email message to multiple accounts, if you enable the tag <img>

    (to include an image) it gets sent in junk emails, but if only plain text is sent to inbox. Does anyone know why this is so? And how to solve it?
+1


source to share


3 answers


You have to submit your email as multipart

using the part text/plain

.



This will allow people with text mail clients to read it, and also count on any spam detection systems in your favor.

+1


source


  • No, some email clients (especially webmail) will deprive something earlier <body>

  • You can use inline styles <div style="">

    - using an external .css file is not recommended as it cannot be loaded.
  • If you only have text and an image, it looks like spam. If you had more text, it could be interpreted in different ways.


0


source


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

here you will find a complete description

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

0


source







All Articles