1

I want to display my logo in my automatic email with swiftmailer. So I have this code:

message = \Swift_Message::newInstance();
    $imgUrl = $message->attach(\Swift_Attachment::fromPath('http://img15.hostingpics.net/pics/419370oah.png'));
$message->setSubject('Demande de devis bien reçue !')
            ->setFrom('xxx@gmail.com')
            ->setTo($devis->getEmail())
            ->setBody(
                $this->renderView(
                    'OAHDevisBundle:Devis:devis_email.html.twig',array('url'=>$imgUrl)
                    ),
                'text/html'
                );

$this->get('mailer')->send($message); 

I try too with

$message->embed(\Swift_Image::fromPath(...)

and the result is the same, my image is not displaying but in attached file.

My template is :

<!DOCTYPE html>
<html>

  <head>

    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

   </head>

   <body>

        <div class="container-fluid">

            <div class="row">
        <div class="col-sm-offset-3 col-sm-6">
          <img src="{{ url }}" alt="Optic at home">
              </div>
      </div>

            <div class="row">
                <h3>Votre devis a bien été reçu!</h3>

                    <p>Bonjour ,nous avons bien  reçu votre demande de devis !<br>
                        Nous vous donnerons une réponse dans les 24h .<br>
                        Merci de nous avoir contacté.<br>
                        Optic at home
                    </p>
      </div>

    </body>
</html>

So send mail works, but my image is not displayed in...
Maybe there's a problem with my template because my HTML tags are not interpreted in my mail.
For example my <br> are useful in my final mail.
I'm sorry for my English. If you want more details just ask.

The "show original message" from gmail :

<h3>Votre devis a bien =C3=A9t=C3=A9 re=C3=A7u!</h3>

Nous vous donn=
erons une r=C3=A9ponse dans les 24h


Merci de nous avoir contact=
=C3=A9.

Optic at home



--_=_swift_v4_1449084877_72d64dd792ab35753394a277bad4f20e_=_
Content-Type: image/png; name=419370oah.png
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=419370oah.png
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Flushdrew
  • 133
  • 1
  • 10
  • you're embedding, which means you need to assign that attachment a CID and refer to it in the image tag: ``. alternatively, embed the image as a data uri: `` – Marc B Dec 02 '15 at 19:08
  • That' what i did no? – Flushdrew Dec 02 '15 at 19:09
  • doh. right. sorry. misssed the $imgurl bit. well, what mailer are you using to read the mail? not all of them support cid: sources for images. – Marc B Dec 02 '15 at 19:12
  • 1
    in the email recieved, can you take a look at "show original email" to see if the url its getting replaced in the engine template? – Mariano Montañez Ureta Dec 02 '15 at 19:13
  • I use gmail to test this.I updated my question to paste the "show original message" form gmail.Thank you – Flushdrew Dec 02 '15 at 19:37
  • Please use search before asking http://stackoverflow.com/questions/15537551/add-inline-image-to-a-message-sent-with-swiftmailer http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment – toor Dec 07 '15 at 18:59

0 Answers0