views:

38

answers:

2

Hello,

I am creating a web application for a client that has the ability to send out emails. I am using TinyMCE for my text editor, which works quite nicely. I am using sendmail() with PHP Swiftmailer to handle the actual sending of the email. Swiftmailer works nicely, as well.

The only problem that I am running into is that when I receive the email (in Gmail), the formatting is not rendered correctly. I am receiving the following in the body of my email:

<p>Oh Hello! This is a test <strong>message</strong>. Here is a link: <a href=\\\"http://www.google.com\\\"&gt;Google&lt;/a&gt;.&lt;/p&gt;\r\n&lt;p&gt;&amp;nbsp;&lt;/p&gt;\r\n&lt;p&gt;&amp;nbsp;&lt;/p&gt;\r\n&lt;p&gt;&amp;nbsp;&lt;/p&gt;\r\n&lt;p&gt;Line breaks!<br /> <br /> Shift breaks!</p>\r\n<p>&nbsp;</p>\r\n<p>Bye!</p>

The links render, and that's about it. What am I missing?

Thanks!

+2  A: 

You need to send your e-mail in an actual HTML format. You are instead sending the plain text of the HTML. The links render because Google is nice and automatically links what it believes to be a valid URL.

I strongly recommend the Pear mail class. There are convenient functions for setting HTML and plain text message bodies.

Brad
+3  A: 

Check out the second and third code blocks in the documentation for how to set the HTML Content-Type...

http://swiftmailer.org/docs/header-parameterized

Cags
Thanks. Is there a difference between setting the charset in the message object as opposed to setting it in the header?
behrk2
To be honest I couldn't say for sure, I'm not familiar with Swift Mailer, I just knew you had to set the header, so Googled for their docs on how to do it. I'd imagine at the end of the day they boil down to the same thing, but one will likely overwrite the other at some point.
Cags