7

I have some basic html and some css but for some reason gmail puts 3D infornt the 'text/css'

Code sample

$message = "
            <style type='text/css'>
              #main {border:1px solid red;}
            </style>

              <div id='main'>some text</div>
";

But when I view the original send to the gmail

<style type=3D'text/css'>

and maybe thats why the mail is not styled. I am using the swift mailer

// also in html

<div id=3D'main'>

// swift mailer

    $type = $message->getHeaders()->get('Content-Type');
    $type->setValue('text/html');
    $type->setParameter('charset', 'utf-8');
Demis Palma ツ
  • 7,669
  • 1
  • 23
  • 28
grape1
  • 759
  • 2
  • 8
  • 19
  • http://en.wikipedia.org/wiki/Quoted-printable#Quoted-printable_encoding <-- This looks useful – jimw May 26 '12 at 02:08

3 Answers3

2

From what I know gmail doesnt support style tag in head or in body. I use style attributes for elements when sending email.

Josnidhin
  • 12,469
  • 9
  • 42
  • 61
2

to let swift mailer send message in HTML format, even for gmail , because swift mailer escape html tags to its represented characters , so you need to write these lines this way:

$message = (new Swift_Message('Message Subject HERE '))
        ->setFrom(array('sender email' => 'Sender Name')) // can be $_POST['email'] etc...
        ->setTo(array('reciever email' => 'Receiver Name')) // your email / multiple supported.
        ->setEncoder( new Swift_Mime_ContentEncoder_PlainContentEncoder('8bit'))
        ->setBody($template, "text/html");

after that every thing should work fine the trick here is to till swift mailer to use Swift mailler MimeType class and point to the correct encoding . you can check here for more information link here

Mohammed Omer
  • 1,168
  • 1
  • 10
  • 17
1

Swift Mailer is trying to escape " to \". You have to use setEncoder() before setBody():

$message->setEncoder(Swift_Encoding::get8BitEncoding());
$message->setBody($body, "text/html");
Demis Palma ツ
  • 7,669
  • 1
  • 23
  • 28
  • This solution does not work for me. I added `$message->setEncoder(Swift_Encoding::get8BitEncoding());` and when I `print_r` the message after sending from on my server, the HTML part is shown as `Content-Transfer-Encoding: 8bit` and the equal signs appear as desired (i.e., just =). However, when receiving this message, the HTML part has been changed to `Content-Transfer-Encoding: quoted-printable` and the equal signs show as `=3D`. Using Swiftmail version Swift-5.4.3. Tried multiple receiving hosts and multiple receiving mail clients, all with the same result. – Jon Aug 24 '16 at 19:37
  • 1
    As mentioned, the `$message->setEncoder(Swift_Encoding::get8BitEncoding());` modification did not fix the issue for me. However, `$message->setEncoder(Swift_Encoding::getBase64Encoding());` encodes the HTML part as `base64` data and this comes through untouched on the other end. This was particularly important to me as not only is the HTML now rendering properly, but I am also signing my messages with an `S/MIME` signature and the received modified message caused the signature to be invalid. Now, the signature remains valid as the message is unmodified on the receiving end. – Jon Aug 25 '16 at 23:26
  • static calling did not work and even it is not in current version 6.1 documentation, use normal new keyword instantiation instead – Mohammed Omer Sep 09 '18 at 20:38