Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ed0e44d2
Commit
ed0e44d2
authored
Nov 07, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor touch up of swiftmailer.
parent
7b910110
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
42 deletions
+49
-42
Mailer.php
extensions/swiftmailer/Mailer.php
+4
-3
README.md
extensions/swiftmailer/README.md
+27
-36
BaseMailer.php
framework/yii/mail/BaseMailer.php
+4
-1
BaseMessage.php
framework/yii/mail/BaseMessage.php
+0
-2
MailerInterface.php
framework/yii/mail/MailerInterface.php
+5
-0
MessageInterface.php
framework/yii/mail/MessageInterface.php
+9
-0
No files found.
extensions/swiftmailer/Mailer.php
View file @
ed0e44d2
...
@@ -7,9 +7,9 @@
...
@@ -7,9 +7,9 @@
namespace
yii\swiftmailer
;
namespace
yii\swiftmailer
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\mail\BaseMailer
;
use
yii\mail\BaseMailer
;
use
Yii
;
/**
/**
* Mailer based on SwiftMailer library.
* Mailer based on SwiftMailer library.
...
@@ -116,13 +116,14 @@ class Mailer extends BaseMailer
...
@@ -116,13 +116,14 @@ class Mailer extends BaseMailer
*/
*/
protected
function
createTransport
(
array
$config
)
protected
function
createTransport
(
array
$config
)
{
{
if
(
array_key_exists
(
'class'
,
$config
))
{
if
(
isset
(
$config
[
'class'
]
))
{
$className
=
$config
[
'class'
];
$className
=
$config
[
'class'
];
unset
(
$config
[
'class'
]);
unset
(
$config
[
'class'
]);
}
else
{
}
else
{
$className
=
'Swift_MailTransport'
;
$className
=
'Swift_MailTransport'
;
}
}
$transport
=
call_user_func
([
$className
,
'newInstance'
]);
/** @var \Swift_MailTransport $transport */
$transport
=
$className
::
newInstance
();
if
(
!
empty
(
$config
))
{
if
(
!
empty
(
$config
))
{
foreach
(
$config
as
$name
=>
$value
)
{
foreach
(
$config
as
$name
=>
$value
)
{
if
(
property_exists
(
$transport
,
$name
))
{
if
(
property_exists
(
$transport
,
$name
))
{
...
...
extensions/swiftmailer/README.md
View file @
ed0e44d2
Yii 2.0 Public Preview - SwiftMailer Mail Solution
SwiftMailer Extension for Yii 2
===============================
===================
===============================
Th
ank you for choosing Yii - a high-performance component-based PHP framework
.
Th
is extension provides a
`SwiftMailer`
mail solution for Yii 2
.
If you are looking for a production-ready PHP framework, please use
To use this extension, simply add the following code in your application configuration:
[
Yii v1.1
](
https://github.com/yiisoft/yii
)
.
Yii 2.0 is still under heavy development. We may make significant changes
```
php
without prior notices.
**Yii 2.0 is not ready for production use yet.**
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
Installation
...
@@ -20,39 +35,15 @@ Installation
...
@@ -20,39 +35,15 @@ Installation
The preferred way to install this extension is through
[
composer
](
http://getcomposer.org/download/
)
.
The preferred way to install this extension is through
[
composer
](
http://getcomposer.org/download/
)
.
Either run
Either run
```
```
php composer.phar require yiisoft/yii2-swiftmailer "*"
php composer.phar require yiisoft/yii2-swiftmailer "*"
```
```
or add
or add
```
json
```
json
"yiisoft/yii2-swiftmailer"
:
"*"
"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
.
framework/yii/mail/BaseMailer.php
View file @
ed0e44d2
...
@@ -7,9 +7,9 @@
...
@@ -7,9 +7,9 @@
namespace
yii\mail
;
namespace
yii\mail
;
use
Yii
;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
Yii
;
use
yii\base\ViewContextInterface
;
use
yii\base\ViewContextInterface
;
/**
/**
...
@@ -46,6 +46,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -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
* @var array configuration, which should be applied by default to any new created
* email message instance.
* email message instance.
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
*
* - 'charset' argument for [[MessageInterface::charset()]]
* - 'charset' argument for [[MessageInterface::charset()]]
* - 'from' argument for [[MessageInterface::from()]]
* - 'from' argument for [[MessageInterface::from()]]
* - 'to' argument for [[MessageInterface::to()]]
* - 'to' argument for [[MessageInterface::to()]]
...
@@ -54,7 +55,9 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
...
@@ -54,7 +55,9 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
* - 'subject' argument for [[MessageInterface::subject()]]
* - 'subject' argument for [[MessageInterface::subject()]]
* - 'textBody' argument for [[MessageInterface::textBody()]]
* - 'textBody' argument for [[MessageInterface::textBody()]]
* - 'htmlBody' argument for [[MessageInterface::htmlBody()]]
* - 'htmlBody' argument for [[MessageInterface::htmlBody()]]
*
* For example:
* For example:
*
* ~~~
* ~~~
* array(
* array(
* 'charset' => 'UTF-8',
* 'charset' => 'UTF-8',
...
...
framework/yii/mail/BaseMessage.php
View file @
ed0e44d2
...
@@ -7,9 +7,7 @@
...
@@ -7,9 +7,7 @@
namespace
yii\mail
;
namespace
yii\mail
;
use
yii\base\InvalidParamException
;
use
yii\base\Object
;
use
yii\base\Object
;
use
yii\helpers\FileHelper
;
use
Yii
;
use
Yii
;
/**
/**
...
...
framework/yii/mail/MailerInterface.php
View file @
ed0e44d2
...
@@ -11,6 +11,7 @@ namespace yii\mail;
...
@@ -11,6 +11,7 @@ namespace yii\mail;
* MailerInterface is an interface, which any mailer should apply.
* MailerInterface is an interface, which any mailer should apply.
* Mailer creates and sends messages. Also it allows composition of the message
* Mailer creates and sends messages. Also it allows composition of the message
* body via view rendering:
* body via view rendering:
*
* ~~~php
* ~~~php
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
* ->from('from@domain.com')
* ->from('from@domain.com')
...
@@ -29,12 +30,16 @@ interface MailerInterface
...
@@ -29,12 +30,16 @@ interface MailerInterface
/**
/**
* Creates new message optionally filling up its body via view rendering.
* 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:
* The view to be rendered can be specified in one of the following formats:
*
* - path alias (e.g. "@app/mails/contact/body");
* - path alias (e.g. "@app/mails/contact/body");
* - relative path (e.g. "contact"): the actual view file will be resolved by [[\yii\base\ViewContextInterface]].
* - 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
* @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
* - 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.
* text body will be composed automatically from html one.
* - if array - list of views for each body type in format: ['html' => 'htmlView', 'text' => 'textView']
* - 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.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return MessageInterface message instance.
* @return MessageInterface message instance.
*/
*/
...
...
framework/yii/mail/MessageInterface.php
View file @
ed0e44d2
...
@@ -11,6 +11,7 @@ namespace yii\mail;
...
@@ -11,6 +11,7 @@ namespace yii\mail;
* MessageInterface is an interface, which email message should apply.
* MessageInterface is an interface, which email message should apply.
* Together with application component, which matches the [[MailerInterface]],
* Together with application component, which matches the [[MailerInterface]],
* it introduces following mail sending syntax:
* it introduces following mail sending syntax:
*
* ~~~php
* ~~~php
* Yii::$app->mail->compose()
* Yii::$app->mail->compose()
* ->from('from@domain.com')
* ->from('from@domain.com')
...
@@ -100,8 +101,10 @@ interface MessageInterface
...
@@ -100,8 +101,10 @@ interface MessageInterface
* Attaches existing file to the email message.
* Attaches existing file to the email message.
* @param string $fileName full file name
* @param string $fileName full file name
* @param array $options options for embed file. Valid options are:
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
*
* @return static self reference.
* @return static self reference.
*/
*/
public
function
attach
(
$fileName
,
array
$options
=
[]);
public
function
attach
(
$fileName
,
array
$options
=
[]);
...
@@ -110,8 +113,10 @@ interface MessageInterface
...
@@ -110,8 +113,10 @@ interface MessageInterface
* Attach specified content as file for the email message.
* Attach specified content as file for the email message.
* @param string $content attachment file content.
* @param string $content attachment file content.
* @param array $options options for embed file. Valid options are:
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
*
* @return static self reference.
* @return static self reference.
*/
*/
public
function
attachContent
(
$content
,
array
$options
=
[]);
public
function
attachContent
(
$content
,
array
$options
=
[]);
...
@@ -121,8 +126,10 @@ interface MessageInterface
...
@@ -121,8 +126,10 @@ interface MessageInterface
* This method should be used when embedding images or other data in a message.
* This method should be used when embedding images or other data in a message.
* @param string $fileName file name.
* @param string $fileName file name.
* @param array $options options for embed file. Valid options are:
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
*
* @return string attachment CID.
* @return string attachment CID.
*/
*/
public
function
embed
(
$fileName
,
array
$options
=
[]);
public
function
embed
(
$fileName
,
array
$options
=
[]);
...
@@ -132,8 +139,10 @@ interface MessageInterface
...
@@ -132,8 +139,10 @@ interface MessageInterface
* This method should be used when embedding images or other data in a message.
* This method should be used when embedding images or other data in a message.
* @param string $content attachment file content.
* @param string $content attachment file content.
* @param array $options options for embed file. Valid options are:
* @param array $options options for embed file. Valid options are:
*
* - fileName: name, which should be used to attach file.
* - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type.
* - contentType: attached file MIME type.
*
* @return string attachment CID.
* @return string attachment CID.
*/
*/
public
function
embedContent
(
$content
,
array
$options
=
[]);
public
function
embedContent
(
$content
,
array
$options
=
[]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment