Commit ed0e44d2 by Qiang Xue

minor touch up of swiftmailer.

parent 7b910110
......@@ -7,9 +7,9 @@
namespace yii\swiftmailer;
use Yii;
use yii\base\InvalidConfigException;
use yii\mail\BaseMailer;
use Yii;
/**
* Mailer based on SwiftMailer library.
......@@ -116,13 +116,14 @@ class Mailer extends BaseMailer
*/
protected function createTransport(array $config)
{
if (array_key_exists('class', $config)) {
if (isset($config['class'])) {
$className = $config['class'];
unset($config['class']);
} else {
$className = 'Swift_MailTransport';
}
$transport = call_user_func([$className, 'newInstance']);
/** @var \Swift_MailTransport $transport */
$transport = $className::newInstance();
if (!empty($config)) {
foreach ($config as $name => $value) {
if (property_exists($transport, $name)) {
......@@ -139,4 +140,4 @@ class Mailer extends BaseMailer
}
return $transport;
}
}
\ No newline at end of file
}
Yii 2.0 Public Preview - SwiftMailer Mail Solution
==================================================
SwiftMailer Extension for Yii 2
===============================
Thank you for choosing Yii - a high-performance component-based PHP framework.
This extension provides a `SwiftMailer` mail solution for Yii 2.
If you are looking for a production-ready PHP framework, please use
[Yii v1.1](https://github.com/yiisoft/yii).
To use this extension, simply add the following code in your application configuration:
Yii 2.0 is still under heavy development. We may make significant changes
without prior notices. **Yii 2.0 is not ready for production use yet.**
```php
return [
//....
'components' => [
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
],
],
];
```
You can then send an email as follows:
[![Build Status](https://secure.travis-ci.org/yiisoft/yii2.png)](http://travis-ci.org/yiisoft/yii2)
```php
Yii::$app->mail->compose('contact/html')
->from('from@domain.com')
->to($form->email)
->subject($form->subject)
->send();
```
This is the yii2-swiftmailer extension.
For further instructions refer to the related section in the Yii Definitive Guide.
Installation
......@@ -20,39 +35,15 @@ Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-swiftmailer "*"
```
or add
```json
"yiisoft/yii2-swiftmailer": "*"
```
to the require section of your composer.json.
*Note: You might have to run `php composer.phar selfupdate`*
Usage & Documentation
---------------------
This extension has to be registered prior to usage.
To enable this view renderer add it to the $rendereres property of your view object.
Example:
```php
<?php
// config.php
return [
//....
'components' => [
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
],
],
];
```
For further instructions refer to the related section in the yii guide.
to the require section of your composer.json.
......@@ -7,9 +7,9 @@
namespace yii\mail;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
use Yii;
use yii\base\ViewContextInterface;
/**
......@@ -46,6 +46,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* @var array configuration, which should be applied by default to any new created
* email message instance.
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
*
* - 'charset' argument for [[MessageInterface::charset()]]
* - 'from' argument for [[MessageInterface::from()]]
* - 'to' argument for [[MessageInterface::to()]]
......@@ -54,7 +55,9 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* - 'subject' argument for [[MessageInterface::subject()]]
* - 'textBody' argument for [[MessageInterface::textBody()]]
* - 'htmlBody' argument for [[MessageInterface::htmlBody()]]
*
* For example:
*
* ~~~
* array(
* 'charset' => 'UTF-8',
......@@ -209,4 +212,4 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
{
return Yii::getAlias($this->viewPath) . DIRECTORY_SEPARATOR . $view;
}
}
\ No newline at end of file
}
......@@ -7,9 +7,7 @@
namespace yii\mail;
use yii\base\InvalidParamException;
use yii\base\Object;
use yii\helpers\FileHelper;
use Yii;
/**
......@@ -58,4 +56,4 @@ abstract class BaseMessage extends Object implements MessageInterface
return '';
}
}
}
\ No newline at end of file
}
......@@ -11,6 +11,7 @@ namespace yii\mail;
* MailerInterface is an interface, which any mailer should apply.
* Mailer creates and sends messages. Also it allows composition of the message
* body via view rendering:
*
* ~~~php
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
* ->from('from@domain.com')
......@@ -29,12 +30,16 @@ interface MailerInterface
/**
* Creates new message optionally filling up its body via view rendering.
* The view to be rendered can be specified in one of the following formats:
*
* - path alias (e.g. "@app/mails/contact/body");
* - relative path (e.g. "contact"): the actual view file will be resolved by [[\yii\base\ViewContextInterface]].
*
* @param string|array $view view, which should be used to render message body
*
* - if string - the view name or the path alias of the HTML body view file, in this case
* text body will be composed automatically from html one.
* - if array - list of views for each body type in format: ['html' => 'htmlView', 'text' => 'textView']
*
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return MessageInterface message instance.
*/
......@@ -55,4 +60,4 @@ interface MailerInterface
* @return integer number of successful sends.
*/
public function sendMultiple(array $messages);
}
\ No newline at end of file
}
......@@ -11,6 +11,7 @@ namespace yii\mail;
* MessageInterface is an interface, which email message should apply.
* Together with application component, which matches the [[MailerInterface]],
* it introduces following mail sending syntax:
*
* ~~~php
* Yii::$app->mail->compose()
* ->from('from@domain.com')
......@@ -100,8 +101,10 @@ interface MessageInterface
* Attaches existing file to the email message.
* @param string $fileName full file name
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
*
* @return static self reference.
*/
public function attach($fileName, array $options = []);
......@@ -110,8 +113,10 @@ interface MessageInterface
* Attach specified content as file for the email message.
* @param string $content attachment file content.
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
*
* @return static self reference.
*/
public function attachContent($content, array $options = []);
......@@ -121,8 +126,10 @@ interface MessageInterface
* This method should be used when embedding images or other data in a message.
* @param string $fileName file name.
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
*
* @return string attachment CID.
*/
public function embed($fileName, array $options = []);
......@@ -132,8 +139,10 @@ interface MessageInterface
* This method should be used when embedding images or other data in a message.
* @param string $content attachment file content.
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
*
* @return string attachment CID.
*/
public function embedContent($content, array $options = []);
......@@ -149,4 +158,4 @@ interface MessageInterface
* @return string the string representation of this message.
*/
public function toString();
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment