Recommend this page to a friend! |
Classes of Adnane EL Mouttaki | Covoiturage | protected/extensions/YiiMailer/README.md | Download |
|
DownloadYiiMailerYii extension for sending emails with layouts using PHPMailer Features
Installation
UsageInstantiate YiiMailer in your controller or console command and pass view and data array: <pre> $mail = new YiiMailer('contact', array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form')); </pre> or <pre> $mail = new YiiMailer(); $mail->setView('contact'); $mail->setData(array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form')); </pre> Layout is automatically set from config but you may override it with <pre> $mail->setLayout('layoutName'); </pre> Set the properties: <pre> $mail->setFrom('from@example.com', 'John Doe'); $mail->setTo(Yii::app()->params['adminEmail']); $mail->setSubject('Mail subject'); </pre> You may use all PHPMailer properties you would usually use. And finally send email(s): <pre> if ($mail->send()) {
} else {
} </pre> Sending simple messagesYou can send email without both the layout and view by using: <pre> $mail = new YiiMailer(); //$mail->clearLayout();//if layout is already set in config $mail->setFrom('from@example.com', 'John Doe'); $mail->setTo(Yii::app()->params['adminEmail']); $mail->setSubject('Mail subject'); $mail->setBody('Simple message'); $mail->send(); </pre> Alternatively, you may also send email message with layout but without specific view (set layout and set body) or with view but without layout (clear layout and set view). Setting addressesWhen using methods for setting addresses (setTo(), setCc(), setBcc(), setReplyTo()) any of the following is valid for arguments: <pre> $mail->setTo('john@example.com'); $mail->setTo(array('john@example.com','jane@example.com')); $mail->setTo(array('john@example.com'=>'John Doe','jane@example.com')); </pre> Sending attachmentsYou may send one or more attachments using setAttachemnt() method: <pre> $mail->setAttachment('something.pdf'); $mail->setAttachment(array('something.pdf','something_else.pdf','another.doc')); $mail->setAttachment(array('something.pdf'=>'Some file','something_else.pdf'=>'Another file')); </pre> Test modeWhen working locally without mail server installed, it may be useful to save emails as files instead of trying to send them and getting errors in the process. To use test mode, you must specify path to directory where you want to save your emails and set 'testMode' property to 'true' in your config: <pre>
</pre> Emails are saved as .eml files and you can use software like Mozilla Thunderbird to open them. ExamplesTwo examples included: one for standard contact form in yii web app and the other one for yii console app. |