Yii 1.1: mail

SwiftMailer wrapper
128 followers

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

Resources

Requirements

  • Yii 1.1.x

Documentation

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->addTo($userModel->email);
$message->from = Yii::app()->params['adminEmail'];
Yii::app()->mail->send($message);

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

#17552 report it
Yatin Mistry 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); 
$message->attach($swiftAttachment);

Enjoy!

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

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

Hi

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.

Thanks

Nair

#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:

'application.extensions.yii-mail.*',

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',
        'encryption'=>'tls',
    ),
    'viewPath' => 'application.views.mail',
    'logging' => true,
    'dryRun' => false
),

works

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

just set like this

$message = new YiiMailMessage;
$message->getHeaders()->addMailboxHeader('From');

and then you can set from like this

$message->setFrom('xxx@gmail.com');

you can read this

#10854 report it
teguh11 at 2012/11/28 12:29am
use setFrom / setSender

how to use setFrom / setSender?? because no effect for me.

#10670 report it
zdenekca at 2012/11/13 11:07am
@Renaud

I believe that you can't set 'from' to be anything you like otherwise you could impersonate organizations (and people)?

Why don't you setup noreply@ account and send emails from this account. I see this being done by everyone else.

cheers

#10669 report it
Renaud at 2012/11/13 08:10am
@zdenekca

Thanks zdenekca for your answer But actually what I want to do is set the sender as an email address that does not exist (like noreply@example.com) From what you're telling me it seems not possible, is it ?

#10664 report it
zdenekca at 2012/11/12 08:39pm
using setFrom

If you want to use $message->setFrom($email) you need to remove username (password) from the main.php and instead set it manually in your code:

Yii::app()->mail->getTransport()->setUsername('admin@example.com');
Yii::app()->mail->getTransport()->setPassword('adminpassword...');

    ....
    $message->setFrom('admin@example.com');

I believe this is because you cannot have sender from one email address while you are actually sending the email from a different email account.

If your sender is always 'admin' then just set it in the main.php file. Otherwise use the method above.

#10662 report it
Vicente Russo at 2012/11/12 06:19pm
@Renaud

Try:

$message->from = "admin@example.com";

Leave a comment

Please to leave your comment.

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