I want use SwiftMailer for send and email when finish an insert into database in my action controller but doesn't work.. I use swiftmailer for FOSUserBundle and it's work very well.. This is the config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
port: false
encryption: ~
auth_mode: ~
spool:
type: file
path: "%kernel.cache_dir%/swiftmailer/spool"
sender_address: ~
antiflood:
threshold: 99
sleep: 0
delivery_address: ~
disable_delivery: ~
logging: "%kernel.debug%"
# Routing
be_simple_i18n_routing: ~
# FOSUserBundle Configuration
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Dt\EcBundle\Entity\User
profile:
form:
type: dt_ec_profile
registration:
confirmation:
enabled: true
form:
type: dt_ec_registration
from_email:
address: ------@------.com
sender_name: ------
service:
mailer: fos_user.mailer.twig_swift
resetting:
email:
template: DtEcBundle:User:resetting.email.html.twig
This is the code of controller:
$container->get('swiftmailer.mailer');
$mailer = \Swift_Mailer::newInstance();
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('------@-----.com')
->setTo('------@-----.com')
->setBody('You should see me from the profiler!')
;
/* // Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
echo "Failures:";
var_dump($failures);
} */
$this->get('mailer')->send($message);
How can i do??