与Symfony Mailer一起发送电子邮件

发布于 2025-02-05 09:24:24 字数 1458 浏览 5 评论 0原文

我有Symfony 5.4的新安装。我遵循了文档,以从我自己的SMTP服务器发送电子邮件,但无法使其正常工作。因此,我正在尝试 https://mailtrap.io/ 带有以下配置,没有运气。任何帮助都将受到赞赏。

遵循的步骤
composer require symfony/mailer
composer require symfonycasts/verify-email-bundle
MAILER_DSN=smtp://d62b667a28d6af:[email protected]:2525
#MAILER_DSN=smtp://d62b667a28d6af:[email protected]:2525?encryption=tls&auth_mode=login

registrationController

// generate a signed url and email it to the user
$this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
    (new TemplatedEmail())
        ->from(new Address('registration@my_host.com', 'Registration Confirmation'))
        ->to($user->getEmail())
        ->subject('Please Confirm your Email')
        ->htmlTemplate('registration/confirmation_email.html.twig')
);

mailer.yml

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

I have fresh installation of Symfony 5.4. I have followed the documentation in order to send email from my own smtp server but couldn't make it work. So, I'm trying https://mailtrap.io/ with the following configurations with no luck. Any help is appreciated.

Steps followed
composer require symfony/mailer
composer require symfonycasts/verify-email-bundle
MAILER_DSN=smtp://d62b667a28d6af:[email protected]:2525
#MAILER_DSN=smtp://d62b667a28d6af:[email protected]:2525?encryption=tls&auth_mode=login

RegistrationController

// generate a signed url and email it to the user
$this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
    (new TemplatedEmail())
        ->from(new Address('registration@my_host.com', 'Registration Confirmation'))
        ->to($user->getEmail())
        ->subject('Please Confirm your Email')
        ->htmlTemplate('registration/confirmation_email.html.twig')
);

mailer.yml

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆萌少年 2025-02-12 09:24:24

运行:

composer require symfony/messenger

然后运行:

php bin/console messenger:consume async

Run:

composer require symfony/messenger

Then run:

php bin/console messenger:consume async
青芜 2025-02-12 09:24:24

如果您使用-docker选项安装了Symfony,则您的Docker-compose.override.yml文件将在添加Symfony Mailer时包含邮件捕捉器的配置。

来自官方Symfony网站: https:// symfony。 com/doc/current/the-fast-track/en/3-Zero.html

-docker:在您的本地计算机上,我们将使用Docker来管理PostgreSQL之类的服务。此选项启用Docker,以便Symfony将根据所需的软件包自动添加Docker服务(例如,在添加symfony Mailer时添加ORM或邮件捕获器时的PostgreSQL服务)。

在您的 profiler bar,悬停在“服务器上”,以揭示一系列选项这是网络邮件。如果您的项目中所述的配置存在,则您的网络邮件将在那里交付。

If you installed Symfony with the --docker option, then your docker-compose.override.yml file will contain a configuration for a mail catcher when you add symfony mailer.

From the official Symfony website: https://symfony.com/doc/current/the-fast-track/en/3-zero.html

--docker: On your local machine, we will use Docker to manage services like PostgreSQL. This option enables Docker so that Symfony will automatically add Docker services based on the required packages (a PostgreSQL service when adding the ORM or a mail catcher when adding Symfony Mailer for instance).

In your Profiler bar, hover over "Server" to reveal an array of options one of which is Webmail. Your webmail will be getting delivered there if the configuration described above exists in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文