julien-its / emails-queue-s4
Symfony Easy Emails Queue Bundle for symfony 4
1.0.10
2018-11-20 19:11 UTC
Requires
- php: >=7.0
- symfony/framework-bundle: >=4.0
- symfony/swiftmailer-bundle: ^3.2
README
emails-queue-s4
功能
您可以使用此服务将您的电子邮件发送到队列系统。所有电子邮件都将存储在您的数据库中以保留日志。您可以直接发送电子邮件或使用队列的cron作业。每次调用处理队列操作时,定义您想发送多少封电子邮件。
安装
使用composer安装
$ composer require julien-its/emails-queue-s4
说明
安装完成后,
使用doctrine在您的数据库中生成新表
$ php bin/console doctrine:migration:diff $ php bin/console doctrine:migration:migrate
创建一个新的电子邮件服务,其中您将定义所有电子邮件方法。我们只添加了一个联系表单电子邮件的示例。
<?php
namespace App\Services;
use \JulienIts\EmailsQueueBundle\Entity\EmailQueue;
class EmailService
{
const DEFAULT_SUBJECT = "My App";
protected $jitsEmailService;
public function __construct(\JulienIts\EmailsQueueBundle\Services\EmailService $jitsEmailService)
{
$this->jitsEmailService = $jitsEmailService;
}
public function contact($message)
{
$config = array(
'template' => 'EmailsQueueBundle:mail:contact.html.twig',
'templateVars' => array('message' => $message),
'emailFrom' => 'from@from.com',
'emailFromName' => 'My app',
'contextName' => 'contact',
'priority' => EmailQueue::HIGH_PRIORITY,
'subject' => self::DEFAULT_SUBJECT.' : Contact',
'emailTo' => 'toemail@to.com',
'emailsBcc' => 'contact@from.com;email2@email.com'
);
$this->jitsEmailService->createNewAndProcess($config);
}
}
注意,您可以将contact.html和电子邮件布局复制到自己的appBundle中以个性化它们。
创建电子邮件队列时有两种可能性
$this->jitsEmailService->createNew($config);
$this->jitsEmailService->createNewAndProcess($config);
createNewAndProcess 将直接处理电子邮件队列并将其发送到您的邮件服务。
发送电子邮件
要发送电子邮件,请在控制器中调用您的服务
$message = array( 'name' => 'Julien Gustin', 'phone' => '+320484010203', 'message' => 'gustin.julien@gmail.com' ); $emailService->contact($message);
定义cron操作
如果您想要批量发送电子邮件,您可以使用以下命令
php bin/console jits:queue:process --limit 30