1

i've to send email on registration . Right now this is what i'm doing ,

$bodymessaage= '<table border="0" cellpadding="0" cellspacing="0" width="100%" >';
$bodymessaage.='</table>'  

my images are live on server and i've set their paths as absolute , i've set these headers

<?php $headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";?>

and in mail function is like this .

mail($to, $subject, $bodymessaage, $headers);

now mail is being sent with with all images and stles that are inline , my question is how do i attach css file that is in head section of my html email in style tags ,Please help me to sort this issue ,

1 Answer 1

2

Use html style tag. I'm not 100% sure, but I believe it should come before the html body.

$bodymessage = '
<style>
   table{
   background-color: blue;
   }
</style>
';
$bodymessaage .= '<table border="0" cellpadding="0" cellspacing="0" width="100%" >';
$bodymessaage .='</table>';

This is just an example, of course.

As mentioned by Fred, <style> tags are ignored by most email clients. So instead of using it, use inline CSS:

$bodymessaage .= '<table style="background-color: blue;" border="0" cellpadding="0" cellspacing="0" width="100%" >';
$bodymessaage .='</table>';
Sign up to request clarification or add additional context in comments.

5 Comments

style tags are ignored by most email clients, especially Google, Hotmail, Yahoo. Best to use inline CSS.
Inline CSS would be style=" " in the HTML element, right?
that is exactly it. The first one will fail for the most part, while the second will work.
Thanks, I didn't know about that.
oh and you forgot a closing semi-colon here $bodymessaage .='</table>' ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.