In my ColdFusion program I create email (HTML/CSS) for one or many recipients, and place it in a .cfm file. The email is nicely formatted. When I run the saved file as a program, the cfmail tag sends the email along to whomever, and that is all working. However, along the way, my formatting gets lost. I understand that there is no reason for my local CSS to be functioning when the email gets to its target. But it would be nice if I could preserve the formatting I started with.

Does anyone have a suggestion about how I might do this.

1

2 Answers

If you're not including the attribute type="html" in your cfmail tag, that could be affecting the formatting of your email. Also, within the cfmail tag, embed your style within in addition to your content. For example:

<cfmail from="[email protected]" to="[email protected]" subject"test" server="mymailserver" type="html"> <html> <head> <style> .test { color: ##cc0000; } </style> </head> <body> <div>This email is in red</div> </body> </html> </cfmail> 
2

Styling emails can be tricky as it's different across clients - there are whole blog articles devoted to this. For example, styles in the head section get ignored in some clients and recognised in others. Sadly, inline styles seems to be the "best" approach.

There is a good overview on the campaign monitor website of what works if which clients:

Mailchimp have a handy tool which will inline styles for you based on your HTML/CSS:

It's also worth including a plain text version for maximum compatibility. You can do that like this:

<cfmail to="[email protected]" from="[email protected]" subject="Hello!" type="html"> <cfmailpart type="text/plain" wraptext="60"> Hello, This is plain text version </cfmailpart> <cfmailpart type="text/html"> <h3>Hello</h3> <p>This is <b>HTML</b> version</p> </cfmailpart> </cfmail> 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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