Yii 1.1: mail

SwiftMailer wrapper

This is an emailing extension that wraps SwiftMailer. This extension also allows you to create emails from view files. For more information about SwiftMailer can do, see http://swiftmailer.org



  • Yii 1.1.x


Please see the phpdocs (it is in fact well-documented). First read through the main phpdoc on the Mail.php file and then the Message.php file (both in the root directory).

Quick example to catch your interest

This is an advanced example. It is not required that you use view files to generate the emails.

$message = new YiiMailMessage;
$message->view = 'registrationFollowup';
//userModel is passed to the view
$message->setBody(array('userModel'=>$userModel), 'text/html');
$message->from = Yii::app()->params['adminEmail'];

Change Log

See Google Code hosting page

Matt Kantor has been so gracious as to provide an update, including:

  • Removed the "debug" option and associated behavior. In its place are the "logging" and "dryRun" options. Logging uses Yii::log() (you can set up a LogRoute to show flashes for the old behavior).
  • Changed class names to be less likely to cause conflicts (requested in several bug reports).
  • Made the extension usable from CConsoleApplication.
  • Plenty of formatting and documentation fixes.

Total 20 comments

#19423 report it
bil at 2015/07/01 04:27am
possible problem with sendSimple() function

instead of

else return $this->getMailer()->send($message);

should be

else return $this->getMailer()->send($message->message);
#19069 report it
alexandernst at 2015/03/08 02:48pm
Error in Swift_Transport_StreamBuffer::_$sequence

If you get this error:

Undefined property: Swift_Transport_StreamBuffer::$_sequence

then change visibility of variable $_sequence from 'private' to 'protected' in 'yii-mail/vendors/swiftMailer/classes/Swift/ByteStream/AbstractFilterableInputStream.php'

#17928 report it
Yii3 at 2014/08/12 04:43am

Hello bandpay, if you don't find soluton then check the Link

#17921 report it
pmaselkowski at 2014/08/11 01:09pm

This should be in components config section.

#17920 report it
bandpay at 2014/08/11 11:00am


Regarding the config

This should be placed in under COMPONENTS. :)

'mail' => array(
    'class' => 'ext.yii-mail.YiiMail',
    'transportType' => 'smtp',
    'transportOptions' => array(
        'host' => 'smtp.gmail.com',
        'username' => 'XXXX@gmail.com',
        'password' => 'XXXX',
        'port' => '465',
    'viewPath' => 'application.views.mail',
    'logging' => true,
    'dryRun' => false

Thanks for the assist everyone

#17552 report it
Yii3 at 2014/07/01 05:30am
From email id not set . IT takes SMTP username.

From email id not set . IT takes SMTP username.

I have tried above solution but not working for me.

#16300 report it
hhardy at 2014/02/07 02:02pm
Amazon SES issues

if you got this error:

Ssl Routines: SSL3_GET_RECORD:wrong version number

This is because Yii-mail use a prehistoric version of swiftMailer.

Update SwiftMailer (located in the "vendor" directory) and it will works.

#15740 report it
dacoder at 2013/12/10 06:52pm
code snippet for attaching a file.

for those of you interesting in attaching pdfs/jpegs or whatever you please, use this -

$swiftAttachment = Swift_Attachment::fromPath($file_path); 


#14472 report it
spk at 2013/08/14 04:36pm

When I use that extension (which is used Swift) to send email with attached file, I figured out that Swift trying to determine content type based on attached file extension, I'm thinking it's not safe decision. Just for a note ;)

#14019 report it
hrnair at 2013/07/12 06:10am
When SMTP host is not accessible, Swift_TransportException


Everything works fine! Thanks for the nice extension.

But if the mail server is not accessible, an exemption is thrown. Swift_TransportException Connection could not be established with host smtp.mysite.com [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]

It may not be a problem if the mail server is extremely reliable and offer maximum connectivity. But how to avoid this? Can we provide a try-catch loop for send function so that if the mail is not send we can take further actions for deferred sending and informing the user appropriately.

Tried providing try-catch and problem solved.

$result; try { $result=Yii::app()->mail->send($message); } catch (Exception $e) { $result=0; }

Here we will get a $result which is more than 0 if there is no exception and the mail is sent.



#13636 report it
Azhar at 2013/06/13 01:11am
Track Bounce Email

How can i Track Bounce Emails

#13417 report it
papryk at 2013/05/28 07:08am
@rajesh chaurasia

Add line:


to config in import section

#13412 report it
rajesh chaurasia at 2013/05/28 03:03am
hi friends

Property "CWebApplication.mail" is not defined. got always .

#12450 report it
SomethingWicked at 2013/03/21 09:22am
Embed image

Using the view you can easily show images. THe only thing that comes to my mind is that probably you have a problem with the src of the image, which has to be an absolute url.

Just guessing.

#12448 report it
staticblue at 2013/03/21 09:03am
Thanks for the extension !

Thanks for the extension !

I too, would like to know how to embed images in the e-mail. Right now, when using a view, the images used in the view are not displayed in the e-mail. Do you have a guide on how to do this ?

Thanks, Jonathan

#12432 report it
Scott Deagan at 2013/03/20 08:08am
Adding attachments, embedding images

How do you:

a) Add an attachment (or multiple attachments). b) Embed an image within the email.

#12350 report it
Cleverson at 2013/03/15 08:45am
How can I send an attachment?

I've trying this:

$uploadedFile = CUploadedFile::getInstance($model,'anexo'); $msg->attach($uploadedFile);

But doesn't work and give no errors... Just a blank page...

#12234 report it
MrJ at 2013/03/08 12:13pm
Setting up a connector to Mircosoft Exchange

This post helped me set up a trusted mail connector to MS Exchange: http://blogs.technet.com/b/sbs/archive/2008/09/18/how-to-configure-trusted-smtp-relay-in-exchange-on-sbs-2008.aspx

#11419 report it
TomaszKane at 2013/01/13 06:11am
Gmail smtp config
'mail' => array(
    'class' => 'ext.yii-mail.YiiMail',
    'transportType' => 'smtp',
    'transportOptions' => array(
        'host' => 'smtp.gmail.com',
        'username' => 'XXXX@gmail.com',
        'password' => 'XXXX',
        'port' => '465',
    'viewPath' => 'application.views.mail',
    'logging' => true,
    'dryRun' => false


#10893 report it
teguh11 at 2012/11/30 02:50am
found how to setFrom

just set like this

$message = new YiiMailMessage;

and then you can set from like this


you can read this

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: jonah
  • Category: Mail
  • Votes: +135 / -3
  • Downloaded: 0 times
  • Created on: Apr 26, 2010
  • Last updated: Nov 9, 2010
  • Tags: swiftmailer