projet-normandie/email-bundle

此包已被废弃,不再维护。没有建议的替代包。

诺曼底 EmailBundle

安装: 594

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 4

分支: 0

开放问题: 0

类型:symfony-bundle

dev-develop 2023-01-22 18:52 UTC

This package is auto-updated.

Last update: 2024-04-22 21:29:07 UTC


README

开发

Scrutinizer Code Quality Build Status

安装

确保全局已安装 Composer,如 Composer 文档中的安装章节所述。

使用 Symfony Flex 的应用程序

打开命令控制台,进入您的项目目录并执行以下操作

$ composer require projet-normandie/email-bundle

未使用 Symfony Flex 的应用程序

步骤 1:下载包

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

$ composer require projet-normandie/email-bundle

步骤 2:启用包

然后,通过将其添加到项目 config/bundles.php 文件中注册的包列表中来启用包

// config/bundles.php

return [
    // ...
    ProjetNormandie\EmailBundle\ProjetNormandieEmailBundle::class => ['all' => true],
];

配置

数据库

为了将您的用户实体链接到此模块,您应添加以下配置:(将 AppBundle\Entity\User 替换为您的用户类)。

官方文档

# Doctrine Configuration - config.yml
doctrine:
    orm:
        resolve_target_entities:
            ProjetNormandie\EmailBundle\Entity\UserInterface: AppBundle\Entity\User

在解析实体后,您可以更新数据库模式。

模块配置

from 需要全局设置。

projet_normandie_email:
    from: "no-reply@projetnormandie.com"
    to: "contact@projetnormandie.com"

注意,在构造邮件时可以覆盖 from。

模块使用

使用示例

use ProjetNormandie\EmailBundle\Entity\Email;
use ProjetNormandie\EmailBundle\Service\Mailer;

    private $mailer;
  
    /**
     * @param Mailer $mailer
     */
    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }
   
    public function sendEemail()
    {
        $mail = new Email();
        $mail
            ->setTargetMail($email)
            ->setSubject($subject)
            ->setBodyHtml($body)
            ->setBodyText($body);

        $this->mailer->send($mail);
    }