Yii Framework Forum: Yiimailmessage Mime Multipart/mixed - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yiimailmessage Mime Multipart/mixed Rate Topic: -----

#1 User is offline   awp.black.69 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 24-February 13

  Posted 24 February 2013 - 12:38 PM

Hey....
I want to sent inline image in mail. I dont want to use img tag which would point to some public accessible image. I know it cant be done by using multipart/mixed content type instead of using text/html but dont know how to do that in YiiMailMessage.
Can somebody help !!
0

#2 User is offline   Scott Deagan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-February 10

Posted 09 August 2013 - 09:43 PM

View Postawp.black.69, on 24 February 2013 - 12:38 PM, said:

Hey....
I want to sent inline image in mail. I dont want to use img tag which would point to some public accessible image. I know it cant be done by using multipart/mixed content type instead of using text/html but dont know how to do that in YiiMailMessage.
Can somebody help !!


I can help. The documentation that explains how to do it is here: Embedding Inline Media Files

And now for a simple Yii example...

In your controller:

  public function actionTest()
  {    
    $message = new YiiMailMessage;
    // Assumes 'someimage.jpg' exists in your 'images' directory.
    $image = Swift_Image::fromPath(dirname(Yii::app()->getBasePath()) . '/images/someimage.jpg');
    $cid = $message->embed($image);    
    $message->view = 'test';
    $message->setBody(array('cid' => $cid), 'text/html');
    $message->subject = 'Example of embedded inline image';
    $message->addTo('you@youremailaddress.com');
    $message->from = Yii::app()->params['adminEmail'];    
    Yii::app()->mail->send($message);
  }


In your protected/views/mail/test.php:

  <b>An embedded inline image:</b><br><br>
  <img src="<?php echo $cid; ?>" alt="WTF went wrong?" />


Hope that this helps others who have been unable to find any examples on the Interwebs.
0

#3 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 12 August 2013 - 04:50 PM

A little ugly but interesting feature is the ability to put data straight into the src attribute of the img tag:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />

Don't be a dick.
0

#4 User is offline   Scott Deagan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-February 10

Posted 14 August 2013 - 10:32 AM

View Postnineinchnick, on 12 August 2013 - 04:50 PM, said:

A little ugly but interesting feature is the ability to put data straight into the src attribute of the img tag:

<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />



If you put the base64 encoded value of the image straight into the <img> tag, some mail clients (like the GMail web client for example) will display the base64 encoded characters instead of an image.
0

#5 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 14 August 2013 - 06:09 PM

Just tested it and it didn't displayed it at all. But Thunderbird handled it well. Anyway, it turns out it's not very useful.
Don't be a dick.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users