mailer

Mailer using PHPMailer
34 followers

EMailer is a simple wrapper for the PHPMailer library, which is bundled. You should keep an eye on this library, since it could be updated and the API could get broken.

Please read the source code comments for licensing information. Please read the phpmailer/LICENCE file for the PHPMailer license.

FAQ

  • Why should I use this extension instead of using the phpmailer directly?

Answer: this is encapsulated as a Yii extension, and you can modify the methods or extend the functionality as you'd like, instead of modifying the original source code :)

  • Why the license was GPL on the download page when the extension is released under LGPL?

Answer: my mistake. The license for this extension is and has always been LGPL.

File checksums

  • 847183726a2e59d8aa5968e2fa6f7597 mailer-2.2.tar.bz2
  • bef73d62003ab84399706c578294cccb mailer-2.2.zip

Resources

Documentation

Requirements

  • Yii 1.0 or above
  • PHPMailer (version 5.0 bundled)

Installation

  • Extract the release file under protected/extensions

Usage

As a normal component:

Usage example, using SMTP as the sending method, creating a component inside a controller:

<?php
$message = 'Hello World!';
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->Host = <your smtp host>;
$mailer->IsSMTP();
$mailer->From = 'wei@example.com';
$mailer->AddReplyTo('wei@example.com');
$mailer->AddAddress('qiang@example.com');
$mailer->FromName = 'Wei Yard';
$mailer->CharSet = 'UTF-8';
$mailer->Subject = Yii::t('demo', 'Yii rulez!');
$mailer->Body = $message;
$mailer->Send();

As an application component:

In the configuration (notice the pathViews and pathLayouts parameters):

<?php
'components'=>array(
   'mailer' => array(
      'class' => 'application.extensions.mailer.EMailer',
      'pathViews' => 'application.views.email',
      'pathLayouts' => 'application.views.email.layouts'
   ),
   // ...
}

In the controller:

<?php
$message = 'Hello World!';
Yii::app()->mailer->Host = 'smtp.yiiframework.com';
Yii::app()->mailer->IsSMTP();
Yii::app()->mailer->From = 'wei@pradosoft.com';
Yii::app()->mailer->FromName = 'Wei';
Yii::app()->mailer->AddReplyTo('wei@pradosoft.com');
Yii::app()->mailer->AddAddress('qian@yiiframework.com');
Yii::app()->mailer->Subject = 'Yii rulez!';
Yii::app()->mailer->Body = $message;
Yii::app()->mailer->Send();

Since this is a wrapper, please see:

Change Log

20090529 2.2

  • Fixed bug (reported by ooaat)

20090516 2.1

  • Added pathViews and pathLayouts configuration parameters, to indicate a path aliases where the view and layout for getView are.
  • Added an empty init() method to make it work as an application component.

20090411 2.0

  • Updated PHPMailer to version 5.0
  • Included getView method.

Total 20 comments

#6712 report it
jacksmirk at 2012/01/31 08:49am
Re:don't show images into view

I had the same problem. In order to put images in your email (not as an attachment) you have to provide an absolute and public url to the image. Can you post your view code?

#6710 report it
janka74 at 2012/01/31 05:34am
don't show images into view

Hi. I have tried your extension: It's very very nice!

I have this problem: I follow your sample:

$html = $this->renderPartial('/mycontroller/myview',array('data'=>$data),true); 
...
Yii::app()->mailer->Body = $html;

my view include some picture, but the email don't show those images.

I see into html: http://prova/demo/images/splash.jpg but the exact path should be: http://www.mysite.com/prova/demo/images/splash.jpg

Can you help me? Thank you

#6689 report it
jacksmirk at 2012/01/28 03:10pm
#5934 Username and Password

5934 Check http://phpmailer.worxware.com/index.php?pg=properties $mailer->Username and $mailer->Password should work fine, they work for me.

#5932 report it
prasetia at 2011/11/27 03:27am
Hello

I have some question, about how to define user and password if my host use those.

#5616 report it
eholsinger at 2011/10/25 04:13pm
thank you

I agree with others, it was very easy to get this plugin working.

#4500 report it
ivica at 2011/07/14 12:40am
Usefull extension

Thanks for this extension, PHPMailer is my favorite php mail library.

#3839 report it
narkomanC at 2011/05/13 02:40am
@prchakal

@prchakal

$html = $this->renderPartial('myview',array('data'=>$data),true);
//OR get view from other controller
$html = $this->renderPartial('/mycontroller/myview',array('data'=>$data),true);
 
...
Yii::app()->mailer->Body = $html;
...
#3834 report it
prchakal at 2011/05/12 10:09pm
Views

Hi,

Can you post a sample getting HTML from a VIEW?

#3406 report it
maschingan at 2011/04/11 05:13am
exceptions

Hello, can you add exceptions in __construct() method? Something like this:

public function __construct($exceptions = false)
{
    $this->_myMailer = new PHPMailer($exceptions);
}
#2674 report it
el chief at 2011/01/26 01:06pm
please explain

why should i use this extension and not just phpmailer by itself in the components folder?

#2006 report it
tonydspaniard at 2010/10/29 03:33pm
thanks

Thank you very much for your efforts. Very easy to use and implement.

#637 report it
danaluther at 2010/04/02 03:48pm
Very easy to use

It was quick and easy to get running.

#923 report it
cinsulan at 2010/01/31 12:14am
HTML parameter

Nice work. I'm not too fond of phpmailer in general because of how it's using both variables and methods to set its state, but it's light weight so I'll get over it.

Most of my emails are html formatted so I added an html argument to the method signature. Let me know if this could be done in a simpler way:

public function getView($view, $vars = array(), $layout = null, $html=true) { $body = Yii::app()->controller->renderPartial($this->pathViews.'.'.$view, array_merge($vars, array('content'=>$this->_myMailer)), true); if ($layout === null) { if($html){ $this->_myMailer->MsgHtml($body); }else{ $this->_myMailer->Body = $body; } } else { if($html){ $this->_myMailer->MsgHtml(Yii::app()->controller->renderPartial($this->pathLayouts.'.'.$layout, array('content'=>$body), true)); }else{ $this->_myMailer->Body = Yii::app()->controller->renderPartial($this->pathLayouts.'.'.$layout, array('content'=>$body), true); } } }

#1130 report it
pangjanne at 2009/12/02 03:48am
debug model!

maybe, wo must modify some code to hiden some exception don't expect; in class.phpmailer.php file about 522st line, i change to: if($this->SMTPDebug) { echo $e->getMessage()."\n"; } so , we can decide the exception based on property SMTPDebug;

#1137 report it
jerry2801 at 2009/11/30 09:29pm
so nice~

thank for share!

#1637 report it
umutau at 2009/05/29 12:27am
Attachment

Expected to use this extension with attachment email

#1669 report it
bitmatix at 2009/05/15 06:58pm
Nearly perfect...

...but I have 2 suggestions:

1.

I'd prefer to you this extension like this:

Yii::app()->mailer->Subject = 'Test';
Yii::app()->mailer->Body = 'Hello world!';

to do this, I've changed the __construct() method to init(), and the added it under components in the "protected/config/main.php" like this:

'components' => array(
  'mailer' => array(
    'class' => 'application.extensions.mailer.EMailer'
  )
)

2.

It would be great, if it's possible to configure the path of the view and layout files, instead of setting this hardcoded in the getView() method. so the whole thing looks like this:

'components' => array(
  'mailer' => array(
    'class' =>  'application.extensions.mailer.EMailer',
    'pathViews' => 'application.views.emails',
    'pathLayouts' =>   'applications.views.emails.layouts'
  )
)

I've already made these changes, so if anybody is interested let me know, and I'll send you my version of EMailer.php.

Anyway, good job!

#1684 report it
tjwallace at 2009/05/10 02:42pm
Greate Extension

Very easy to use, just follow the documentation and the examples included in the PHPMailer package (http://sourceforge.net/project/showfiles.php?group_id=26031&package_id=252700)

#1781 report it
will at 2009/04/07 06:08pm
Works fine with Phpmailer v5.0

I was about to write a Phpmailer wrapper and found someone already built it up. Just tested it with the latest PHPMailer V5.0, works well( both mail and smtp ), the GetView() addition function by kvl is a must have as well, they work like a charm. Recommend to everyone who need an feature rich email function in his/her app.

#1795 report it
kvl at 2009/04/02 05:07am
some addition

Very nice and very useful! In order to get a good view usability, I've added the method GetView() to the Emailer class (borrowed from "emailer" extension - see details here) - and all have become just perfect!

public function GetView($view, $vars = array(), $layout = null)
{
        $body = Yii::app()->controller->renderPartial('application.views.email.'.$view, array_merge($vars, array('email'=>$this->myMailer)), true);
        if ($layout === null) {
            $this->myMailer->Body = $body;
        } else {
            $this->myMailer->Body = Yii::app()->controller->renderPartial('application.views.email.layouts.'.$layout, array('content'=>$body), true);
        }
}

Leave a comment

Please to leave your comment.

Create extension