从symfony发送PHP邮件

我想问一下如何从Symfony框架(组件symfony邮件程序)发送PHP mail()。

"symfony/mailer": "5.0.*",

Dsn

MAILER_Dsn=mail://localhost

控制器方法:

public function test(): Response
{
    $transport = new EsmtpTransport('localhost');
    $mailer = new Mailer($transport);

    $username = $this->getUser()->getusername();

    /** @var Users $user */
    $user = $this->getDoctrine()->getRepository(Users::class)->findOneBy(['username' => $username]);

    if (!$user)
        return new Response("User $username not found! Email not tested.");

    $to = $user->getEmail();

    if ($to) {
            $email = new Email();
            $email->from('test@mydomain.com');
            $email->to($to);
            $email->subject('Test mail');
            $email->text('This is test mail from ... for user ' . $to);
            $mailer->send($email);

            return new Response('Mail send!');
    }

    return new Response('Mail not sent - user email information missing!');
}
iCMS 回答:从symfony发送PHP邮件

如果我正确理解了您的问题,那么您想使用新的symfony邮件程序组件来发送电子邮件

前段时间我使用mailer组件编写了一个mailService,也许您可​​以从中得到一些启发?

No implicit argument of type Concurrent[F_],

您将必须根据邮件程序参数配置MAILER_DSN

https://symfony.com/doc/current/components/mailer.html

在文档内,您将找到如何处理一些常见的邮件程序或自行进行配置

祝你好运,玩得开心:)

本文链接:https://www.f2er.com/2163164.html

大家都在问