visual-craft/email-types-bundle
Composer 安装命令:
composer require visual-craft/email-types-bundle
包简介
Symfony Bundle for structured email composing
README 文档
README
Symfony Bundle for structured email composing.
Installation and configuration
Step 1: Install the bundle
composer require visual-craft/email-types-bundle
Step 2: Enable the bundle
If you are not using Flex, you also have to enable the bundle by adding the following line in the app/AppKernel.php:
<?php // config/bundles.php return [ // ... VisualCraft\EmailTypesBundle\VisualCraftEmailTypesBundle::class => ['all' => true], // ... ];
Configure bundle (optional)
# config/packages/email_types.yaml visual_craft_email_types: # used in case of email 'from' is not explicitly set (default null) default_email_from: 'Name <contact@example.com>'
Usage
Create email type class
<?php namespace App\EmailType; use App\Entity\User; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\OptionsResolver\OptionsResolver; use VisualCraft\EmailTypesBundle\EmailTypeInterface; class UserActivationType implements EmailTypeInterface { public function configureOptions(OptionsResolver $optionsResolver): void { $optionsResolver ->setRequired(['user']) ->setAllowedTypes('user', User::class) ; } public function configureEmail(TemplatedEmail $email, array $options): void { $user = $options['user']; $email ->to($user->getEmail()) ->from('admin@example.com') // subject is automatically translated // translation parameters are populated from context (scalar values only) ->subject('Hello %fullName%') ->htmlTemplate('email/activation.html.twig') ->context([ 'user' => $user, // used as subject translation parameter %fullName% 'fullName' => $user->getFullName(), ]) ; } }
Register your email type class as a service
# config/services.yaml services: Email\Type\UserActivationType: ~
Send the email
<?php namespace App\Controller; use App\Entity\User; use App\EmailType\UserActivationType; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use VisualCraft\EmailTypesBundle\Mailer; class ActivationController extends AbstractController { private Mailer $mailer; public function __construct(Mailer $mailer) { $this->mailer = $mailer; } public function __invoke(Request $request): Response { // ...code $this->mailer->send(UserActivationType::class, [ 'user' => $this->getUser(), ]); // ...code } }
Tests
$ vendor/bin/simple-phpunit install $ vendor/bin/simple-phpunit
Additional Tools
$ composer install $ vendor/bin/php-cs-fixer fix $ composer lint
Credits
Developed by Visual Craft.
License
This bundle is under the MIT license. See the complete license in LICENSE file.
visual-craft/email-types-bundle 适用场景与选型建议
visual-craft/email-types-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.09k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 visual-craft/email-types-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 visual-craft/email-types-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 24.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-22