buuum/mail

v1.0.3 2016-12-13 11:34 UTC

This package is auto-updated.

Last update: 2024-09-17 19:49:26 UTC


README

安装

系统要求

使用 Buuum\Mail 需要 PHP >= 5.5.0,但建议使用 PHP 的最新稳定版本。

Composer

Buuum 在 Packagist 上可用,可以使用 Composer 进行安装

composer require buuum/mail

手动

只要您的自动加载器遵循 PSR-0 或 PSR-4 标准,您就可以使用自己的自动加载器。只需将 src 目录的内容放入您的 vendor 目录中。

初始化

use Buuum\Mail;
use Buuum\MailerHandler\SwiftMailerHandler;
use Buuum\MailerHandler\PhpMailerHandler;

$config = [
    'smtpsecure'      => 'tls',
    'host'            => "smtp.host.com",
    'username'        => "host_username",
    'password'        => "host_password",
    'port'            => 25,
    'from'            => ['from@host.com', 'WebName'],
    'response'        => ['response@host.com', 'WebName'],
    'spool'           => true,
    'spool_directory' => __DIR__ . '/spool'
];

// SWIFTHANDLER
$handler = new SwiftMailerHandler($config);
// PHPMAILER HANDLER
$handler = new PhpMailerHandler($config);

$mail = Mail::getInstance();
$mail->setHandler($handler);

 发送邮件

$mail->subject('subject')->to('email@to.com')->body('message body');
$mail->AddAttachment(__DIR__ . '/i.jpg', 'imagen.jpg');
$mail->AddAttachment("http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg", 'car.jpg');
$mail->send();

## 使用 swiftmailer spool 发送邮件 此代码将邮件保存在队列中。

$mail->subject('subject')->to('email@to.com')->body('message body');
$mail->AddAttachment(__DIR__ . '/i.jpg', 'imagen.jpg');
$mail->AddAttachment("http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg", 'car.jpg');
$mail->send(false);

发送邮件队列

$handler->sendSpooledMessages($messageLimit = 100, $timeLimit = 60);

多次发送

$mails = [
    'email1@example.com',
    'email2@example.com',
    'email3@example.com'
];

$mail->subject('subject')->body('message body');

foreach($mails as $mail){
    $mail->to($mail)->send();
}