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
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).
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);
See Google Code hosting page
Matt Kantor has been so gracious as to provide an update, including:
Total 20 comments
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.
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
How do you:
a) Add an attachment (or multiple attachments). b) Embed an image within the email.
I've trying this:
$uploadedFile = CUploadedFile::getInstance($model,'anexo'); $msg->attach($uploadedFile);
But doesn't work and give no errors... Just a blank page...
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
works
just set like this
and then you can set from like this
you can read this
how to use setFrom / setSender?? because no effect for me.
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
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 ?
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.
Try:
$message->setFrom("admin@example.com"); has no effect for me. All the other options are fine (subject, body...) but the "from" is always the email address used in the username of main.php. Any idea why ?
Hi!
How to configure this ext with Gmail?
I tried :
I get :
I also tried :
wich gives this :
Help, please?
Cheers!
@jdm instead of modifying the setSubject($subject) function, simply add the following code at the end of registerScripts() function in YiiMail.php
What this does is set correct encoding (i assume you have charset defined in main config) and encodes the subject automatically (the same way you did).
To be able to use the sendSimple() function replace line 181 in YiiMail.php:
with
@jedi-m
is not only an ugly solution, it is THE solution :) at least with mail() when you have to use it if you have accented / non-latin characters.
The explanation is here. Quote:
Subject of the email to be sent.
Caution
Subject must satisfy » RFC 2047.
In order to use file translation for views you should include this line at YiiMailMessage.php:
First of all, I would like to thank you for this extension.
I would like to know if there is a way to configure it so as to start my defaul mail application with the mail so that I may view it in my mail application and do any modification there before sending. This would be so nice.
Thanks for your reply beforehand
@ploaiza
the YiiMailMessage wrapper the Swift_message instance . and you can pass any method to the underlying swift_message obj from yiimailmessage obj :
the usage is same to Swift_message
Leave a comment
Please login to leave your comment.