Page 1 of 1

PHP Mime Email and CSS

Posted: Tue Mar 20, 2007 6:40 pm
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.

Posted: Tue Mar 20, 2007 6:52 pm
by feyd
The <style> tag is specified to only be valid in when inside the <head> tag.

Posted: Wed Mar 21, 2007 2:53 am
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"));