Text formatting doesn't appear in emails that have been formatted using TinyMCE and sent using SwiftMailer

I use SwiftMailer in my PHP scripts to send emails and I use TinyMCE as a text editor to write and format the message body. The problem is that when I send the message it appears without any formatting in all email clients (gmail, yahoo and hotmail), and even links doesn't appear as links, they appear as normal text but in blue. so what is the problem?

Here is the code I use to send emails:


require_once 'path/to/SwiftMailer/lib/swift_required.php';

$transport = Swift_MailTransport::newInstance();
# Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
# Create the message
$msg = Swift_Message::newInstance();
# Give the message a subject
# Set the From address with an associative array
$msg->setFrom(array($_POST['sender_email'] => $_POST['sender_name']));
# Give it a body
$msg->setBody($_POST['message'], 'text/html');

$failedRecipients = array();
$numSent = 0;
$to = array(
    'recipient_2@yahoo.com' => 'Recipient 2',
    'recipient_4@gmail.com' => 'Recipient 4',

foreach ($to as $address => $name) {
    if (is_int($address)) {
    } else {
        $msg->setTo(array($address => $name));

    $numSent += $mailer->send($msg, $failedRecipients);

echo $numSent > 0 ? 'SUCCESS' : 'FAILURE';


note that $_POST['message'] holds body of the message that I have written and formatted using TinyMCE.


I have tried many things till I figure it out, the problem was that special characters in the formatted message body was being escaped (a back slash was being added in the front of each special character) I don't know why, and I don't know which of them (TinyMCE or SwiftMailer) that did this. So all I needed to do is to strip slashes out of the message body before sending the message throught SwiftMailer. I have just needed to change this line:

$msg->setBody($_POST['message'], 'text/html');

to be:

$msg->setBody(stripslashes($_POST['message']), 'text/html');

Need Your Help

How to extract each color bar and copy them in a table?

excel excel-formula spreadsheet diagram libreoffice

I made a diagram to show unique columns with several colors in each, as shown in the picture.

Best LDAP server to be used with Java EE

java java-ee ldap

I am going to build a Web application that will interact with LDAP.

How can I force Linq to SQL NOT to use the cache?


When I make the same query twice, the second time it does not return new rows form the database (I guess it just uses the cache).