chris13/mail-bundle

加载内容并发送邮件。

1.3.6 2018-08-19 09:26 UTC

README

SensioLabsInsight

邮件组件

安装

步骤 1: 下载组件

打开命令行控制台,进入您的项目目录并执行以下命令以下载此组件的最新稳定版本

$ composer require chris13/mail-bundle "~1"

此命令要求您全局安装了Composer,具体请参考Composer文档中的安装章节

步骤 2: 启用组件

然后,将组件添加到项目app/AppKernel.php文件中已注册组件的列表中,以启用该组件

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Chris\Bundle\MailBundle\MailBundle(),
        );

        // ...
    }

    // ...
}

步骤 3: 配置组件

在您的config.yml文件中添加以下配置

mail:
    sendgrid:
        user: sendgrid_user
        password: sendgrid_pass
        options:
            turn_off_ssl_verification: true

使用方法

对于SendGrid

<?php

$categories = array('category1');

$mailer = $this->get('mail_bundle.send_grid_mailer');
$mailer->setCategories($categories)
       ->prepare($from, $fromName, $to = ['test@yopmail.com'], $subject, $body)
       ->send();

对于SwiftMailer

<?php

$mailer = $this->get('mail_bundle.swift_mailer');
$mailer->prepare($from, $fromName, $to = ['test@yopmail.com'], $subject, $body)
       ->send();

测试

在组件中运行单元测试

$ ./bin/phpunit --debug -c ./