Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swiftmailer and Symfony2

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?

like image 962
Ascherer Avatar asked Jun 07 '11 16:06

Ascherer


People also ask

What is SwiftMailer?

Swift Mailer is a component based library for sending e-mails from PHP applications.

What is SwiftMailer in laravel?

Laravel provides a clean, simple API over the popular SwiftMailer library. Laravel provides drivers for SMTP, Mailgun, Mandrill, Amazon SES, PHP's mail function, and sendmail , allowing you to quickly get started sending mail through a local or cloud based service of your choice.

What is Symfony mailer?

Symfony's Mailer & Mime components form a powerful system for creating and sending emails - complete with support for multipart messages, Twig integration, CSS inlining, file attachments and a lot more. Get them installed with: $ composer require symfony/mailer.


1 Answers

$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

like image 95
kapa Avatar answered Sep 26 '22 06:09

kapa