tags:

views:

53

answers:

1

I can't seem to get multiple css classes working with php's mail, I've gotten inline styles to work just fine but when I try to associate classes with elements it's a no go..

Yes, I know there are other options that are probably better than php's mail. Yes, the classes are local and not from an external style sheet.

Only 1 class will show up out of the two specified and it's always the first one.

If I put class="class1 class2" class1 shows, if I put class="class2 class1" class 2 shows.

What's going on?

Here is my test mail.

$msg = '
        <html>
        <head>
        <style type="text/css">
        .class1{background-color:red;}
        .class2{color:blue;}
        </style>
        </head>
        <body>
        <div class="class2 class1">this is a test</div>
        </body>
        </html>';

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

        @mail($to, $sub, $msg, $headers);
+2  A: 

The PHP mail() function simply sends the text you give it. You can check whether it is working by looking at the raw source of the email in your email client application. If it is all there, then the mail function is working (and I would be shocked if it wans't).

Your issue is probably that your mail client does not support your css. Mail clients generally handle only very simple styling, so you may want to rethink your email layout.

Scott Saunders
+1 CSS in email should only be used inline and never declared in the head (many clients strip this section) nor should it be linked externally. It makes for messy and redundant markup but that's how it goes...
Sonny Boy
Good call, I just sent the test message to my webmail instead of outlook and there was no formating at all...
payling