PHP Mime Email and CSS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
darleyboy
Forum Newbie
Posts: 2
Joined: Tue Mar 20, 2007 6:30 pm

PHP Mime Email and CSS

Post by darleyboy »

Hello to all, first time poster...

I am an intermediate php programmer. I have developed a site that will distribute certificates that are emailed to the user at the end of the site visit. I use Pear mine email to send an html version of the certificate. Until recently, the CSS for the mime attachment was inline, but then I switched the CSS to a style tag that was appended to the begining of the table's html code. Everything worked for a bit, and now it doesn't.

Does anyone have any experience with sending CSS information for Html Mime email for PHP. For now I am going to go back to the inline declarations, but I would rather send a seperate CSS attachment (tried this, couldn't get it to work) with the email.

Thanks in advance for any help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The <style> tag is specified to only be valid in when inside the <head> tag.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Some clients don't deal with CSS very well when it's not embedded inline. For the most solid solution I would personally just bite the bullet and sprinkle your code with the CSS directly.

EDIT | "Some clients" includes Thunderbird too (last I tried)

EDIT 2|
but I would rather send a seperate CSS attachment (tried this, couldn't get it to work) with the email
Using Swift:

Code: Select all

$css = new Swift_Message_EmbeddedFile(new Swift_File("/path/to/css_file.css"));

$message->attach(new Swift_Message_Part(
    "<html><head>
    <link rel=\"stylesheet\" href=\"" . $message->attach($css) . "\" />
    etc etc etc
    ", "text/html"));
Post Reply