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.
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 :)
Answer: my mistake. The license for this extension is and has always been LGPL.
You must place the images in a public HTTP server, since you're using the tag in your view.
protected/extensionsUsage example, using SMTP as the sending method, creating a component inside a controller:
$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();
In the configuration (notice the pathViews and pathLayouts parameters):
'components'=>array( 'mailer' => array( 'class' => 'application.extensions.mailer.EMailer', 'pathViews' => 'application.views.email', 'pathLayouts' => 'application.views.email.layouts' ), // ... }
In the controller:
$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:
Total 20 comments
I have two Questions : 1. how i send with server mail ? 2. how i get error when send mail for validate in my code and dont see error to my user. thanks
I have had a really serious privacy issue (it is my fault) but it would be fine if you add to this brief some reminders.
If you use Emailer extension as a component and you use it in that way:
REMEMBER! it is not a fresh object, so if you loop to send the same mail to several addresses you will (maybe) need to:
Otherwise you will generate emails with "visible" addresses in the "To" field. I didn't realize about that because I was in a hurry and it was problematic.
Thanks, the extension is really useful.
Hi, is there any way to hide the X-Originating-IP in header for security reason??
Awesome used the wrapper very nice, for those who want to test smtp on Windows use this awesome dummy smtp application SMTP Tool
PHPMailer 5.2.2 has new feature called "Callbacks".
The documentation says:
**NEW CALLBACK FUNCTION:**
We have had requests for a method to process the results of sending emails through PHPMailer. In this new release, we have implemented a callback function that passes the results of each email sent (to, cc, and/or bcc). We have provided an example that echos the results back to the screen. The callback function can be used for any purpose. With minor modifications, the callback function can be used to create CSV logs, post results to databases, etc.
Well, it is easy in PHPMailer but I have no idea how to use it within Yii framework with MetaYii extension wrapper. Anybody can advise, please?
UPDATE:
The solution is to place the callback function in an application helper component and then pass the result to controller as application parameter.
I hope this might be helpful.
I think it would be more useful if:
Author change
to
and fix the method "getView" as follows
That fix allow you to set $pathViews and $pathLayouts attributes from the component config
and pass the arbitrary view name to the method "getView"
@prchakal, @briiC.lv and others somebody!
You can just use this for set view:
And if have a model use this:
Hello, is it possible to put smtp server and credentials in config/main.php ?
After updating from PHP 5.2 to 5.3, getView() in the EMailer-Class stopped working. I got an error message in
telling me, that parameter 1 needs to be a valid callback and there is no function "renderPartial" in EMailer class. After further investigation, I found that the error comes from invoking $mailer->getView(), the else-part which will be applied when the class is called without a Yii CController (e.g. from a cron job or console application). If any of you need it, here is the else part, where I only changed the $body- and the second return-statement.
Just a note for anyone trying to send an html email, I had to call this method to get html to render correctly:
It depends on what you are trying to achieve. For example, if you want to send an email when a client creates an order in your store you'd have to put your code in the actionCreate() of the OrderController class.
Where should I put the code "in the controller"? Thank you. :)
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?
Hi. I have tried your extension: It's very very nice!
I have this problem: I follow your sample:
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
I agree with others, it was very easy to get this plugin working.
Thanks for this extension, PHPMailer is my favorite php mail library.
@prchakal
Hi,
Can you post a sample getting HTML from a VIEW?
Hello, can you add exceptions in __construct() method? Something like this:
Thank you very much for your efforts. Very easy to use and implement.
Leave a comment
Please login to leave your comment.