sobit/swiftmailer-component

为基于Yii框架的应用程序提供的组件,它为Swift Mailer库提供简单的配置接口。

dev-master 2014-06-04 18:50 UTC

This package is not auto-updated.

Last update: 2024-09-24 00:19:39 UTC


README

基于Yii框架的应用程序组件,它为Swift Mailer库提供简单的配置接口。

安装

将依赖添加到您的composer.json文件中

{
    "require": {
        "sobit/swiftmailer-component": "dev-master"
    }
}

更新您的protected/config/main.php文件

<?php

Yii::setPathOfAlias('vendor', dirname(__FILE__) . '/../../vendor');

return array(
    'components' => array(
        'mailer' => array(
            'class' => 'vendor.sobit.swiftmailer-component.SwiftMailerComponent',

            'swiftBasePath' => dirname(__FILE__) . '/../../vendor/swiftmailer/swiftmailer',

            'host'     => 'localhost', // smtp host
            'port'     => 25,          // smtp port
            'username' => null,        // username
            'password' => null,        // password
            'security' => null,        // security, e.g. "ssl"
        ),
    ),
);

使用方法

最简单的使用示例

$message = Yii::app()->mailer
    ->createMessage('Test subject', 'Test body content')
    ->setFrom(array('john@doe.com' => 'John Doe'))
    ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
;
Yii::app()->mailer->send($message);