0

I am using php/Mail_mime to send styled html content using the code below.

$headers = array ('From' => $sender,
          'To' => implode(',',$to), 
          'Subject' => $subject,
          'Reply-To'=>'myemail@mydomain.com',
          'MIME-Version'=>'1.0',
          'Content-Type'=>'text/html'
    ); 
    /*end header*/

    $this->mime = new Mail_mime();
    $tt=$this->mime;
    $tt->addBcc(implode(',',$bcc));
    $tt->addCc(implode(',',$cc));
    $tt->setTXTBody($text);
    $tt->setHTMLBody($body);
    $tt->addHTMLImage('../images/delete.gif');
//  $tt->addAttachment('../images/delete.gif','image/gif');
    $mime_body = $tt->get();
    $mime_hdrs = $tt->headers($headers);

    $smtp = Mail::factory('smtp',
    array ('host' => $this->host,
            'port' => $this->port, 
            'auth' => false, 
            'username' => $this->username, 
            'password' => $this->password)); 
    $recipients=array_merge($to,$cc,$bcc);
    $mail = $smtp->send($recipients, $mime_hdrs, $mime_body);

This is all a class code, so initialization is done on the constructor, which is not posted here.

Now my question is, while the above code works fine, i didnt see the correct style on the email sent.

for example if i have this as a message body of my email:

<div style="background-color:silver;">

<h1>MY Header</h1> </div>

On my email, I can only see the My Header. The background didnt showup as silver.

What did i miss on my code above. Any help ?

tkt986
  • 1,081
  • 3
  • 17
  • 25
  • duplicate of https://stackoverflow.com/questions/536838/php-attaching-an-image-to-an-email – dAm2K Jun 05 '17 at 23:15

1 Answers1

0

Its quite possible that the email provider you are using doesn't allow HTML code in the emails, or it restricts CSS styling in the allowed HTML code. Which email provider are you using?

You might want to test this by sending an email to a gmail.com email address, which does allow html code, and see if it makes any difference.

Another thing to test would be to do a view source, or inspect element if you're using google chrome or firebug in firefox, and see if the html code is being placed where it should be.

Ali
  • 261,656
  • 265
  • 575
  • 769
  • @Click Upvote - **My Header** is displayed, assuming HTML is accepted. – ajreal Nov 29 '10 at 22:39
  • @ajreal Its possible that they allow some html tags like h1, b, etc but not allow others like div, span. I recommend that you try another email provider like gmail – Ali Nov 30 '10 at 19:55
  • Sorry I didnt mention that, but i got the same result when i send to gmail, yahoo and 1and1. I am sending from 1and1 domain. – tkt986 Dec 01 '10 at 12:20
  • @tsegay Send a regular email through php's mail function, and put the same HTML code in that. If that works, then most likely you have a problem with the configuration of the mail/mime library – Ali Dec 01 '10 at 12:42