首页 > 解决方案 > Symfony,组件 Mailer Error 发送邮件

问题描述

在我的项目 Symfony 中,我使用 Mailer 组件发送电子邮件,但我发现了这个错误

无法与主机“ssl://smtp.gmail.com:465”建立连接:stream_socket_client():无法连接到 ssl://smtp.gmail.com:465(Une tentative de connexion a échoué car le parti connecté n'a pas répondu convenablement au-delà d'une certaine durée ou une connexion établie a échoué car l'hôte de connexion n'a pas répondu。

控制器中的代码php:

/**
         * @Route("/send", name="send.mail")
         */
        public function testSendMail(MailerInterface $mailer): Response{
            $email = (new Email())
                ->from('test@gmail.com')
                ->to('test1@gmail.com')
                //->cc('cc@example.com')
                //->bcc('bcc@example.com')
                //->replyTo('fabien@example.com')
                //->priority(Email::PRIORITY_HIGH)
                ->subject('Time for Symfony Mailer!')
                ->text('Sending emails is fun again!')
                ->html('<p>See Twig integration for better HTML integration!</p>');

            $mailer->send($email);
            return new Response('send');
        }

.env 文件中的代码配置:

MAILER_DSN=gmail://test@gmail.com:testpwd@localhost?encryption=tls&auth_mode=oauth

如何准确配置发送邮件

标签: phpsymfonymailer

解决方案


推荐阅读