1

在 symfony4 上使用 composer 安装 swiftmailer 之后

composer require mailer

我写了一个小函数来测试它

/**
 * @Route("/testmail", name="testmail")
 */
public function mailAction(\Swift_Mailer $mailer)
{
    $message = (new \Swift_Message('Hello Email'))
        ->setFrom('test@gmail.com')
        ->setTo('test@gmail.com')
        ->setBody('Test content')
    ;

    $mailer->send($message);

    return $this->redirectToRoute('rotta');
}

邮件程序 URL 在 .env 中相应配置

MAILER_URL=gmail://myaccount:mypassword@localhost

但是通过调用我的函数,我收到以下错误消息

Cannot determine controller argument for "App\Controller\RottaController::mailAction()": the $mailer argument is type-hinted with the non-existent class or interface: "Swift_Mailer".

当我执行

./bin/console debug:config framework

swiftmailer没有出现,是服务注册失败了吗?我要检查什么?

谢谢塞巴斯蒂安

4

0 回答 0