我如何在symfony的PHP代码中使用Swift邮件程序

Ran*_*ngh 1 php symfony doctrine-orm

我正在使用此但我收到错误

foo_bundle.listener.comment:
        class: xxx\Listener\CupleListener
        arguments: [@mailer]
Run Code Online (Sandbox Code Playgroud)
class CupleListener
{
    protected $mailer;

    public function __construct(Swift_Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    public function onCenterEvent(CupleEvent $event)
    {
        $center = $event->getcenter();

            $message = \Swift_Message::newInstance()
            ->setSubject('New comment posted on ' . $post->getTitle())
            ->setFrom('send@example.com')
            ->setTo('xxxxxxxxxx')
            ->setBody("Hey, somebody left a new comment on a post you're subscribed to! It says: " . $comment->getBody());
            $this->mailer->send($message);

    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误的

此外,我不知道哪个类包含在命名空间的顶部

fko*_*ler 7

试试:

public function __construct(\Swift_Mailer $mailer)
{
    $this->mailer = $mailer;
}
Run Code Online (Sandbox Code Playgroud)