Mirage
Mirage

Reputation: 31568

How can i use Swift mailer in my php code in symfony

I am using this but i am getting error

foo_bundle.listener.comment:
        class: xxx\Listener\CupleListener
        arguments: [@mailer]

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('[email protected]')
            ->setTo('xxxxxxxxxx')
            ->setBody("Hey, somebody left a new comment on a post you're subscribed to! It says: " . $comment->getBody());
            $this->mailer->send($message);

    }
}

This is giving error

Also i don't know which class to include on the top of namespace

Upvotes: 1

Views: 2264

Answers (1)

fkoessler
fkoessler

Reputation: 7276

Try with:

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

Upvotes: 7

Related Questions