Swiftmailer and Symfony2
Asked Answered
L

1

5

Having some problems implementing swiftmailer with the new symfony2 beta4, below is my code

$mailer = $this->container->get('mailer');
$name = ucwords(str_replace('.',' ', $user->getScreenName()));
$email = '[email protected]'; //$user->getEmail();
$message = $mailer::newInstance()
        ->setSubject('New Password')
        ->setFrom('Neokeo <[email protected]>')
        ->setTo("$name <$email>")
        ->setBody($this->renderView('MyBundle:User:reset.html.php', array('user',$user)));

$mailer->send($message);

and the error

Catchable fatal error: Argument 1 passed to Swift_Mailer::newInstance() must implement interface Swift_Transport, none given

does anyone have any idea what i can do to fix this?

Llewellyn answered 7/6, 2011 at 16:44 Comment(0)
D
9

$mailer is an instance of the Swift_Mailer class (which is the class used for sending messages), but for creating a message, you need the Swift_Message class.

$message = Swift_Message::newInstance()

http://swiftmailer.org/docs/message-quickref

Dilettantism answered 7/6, 2011 at 17:0 Comment(2)
for namespace reasons there should be a \ in front of the Swift_Message. I swear i tried this before and it was giving a different error, but it worked this time. So thank you :)Llewellyn
@Llewellyn Sorry, never touched Symfony before :).Dilettantism

© 2022 - 2024 — McMap. All rights reserved.