I'm new on Symfony.. I would send an email with swift mailer but i don't understand if this service is enabled from FOSUserbundle or not..
I write this code in Controller:
$this->get('mailer')->send($message);
$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))
{
var_dump($failures);
}
IN config.yml i have this for FOSUserBundle
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# 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: consulent
service:
mailer: fos_user.mailer.twig_swift
resetting:
email:
template: DtEcBundle:User:resetting.email.html.twig
How can i do for send and email? Thanks
Edit with parameters.yml
# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: -----
database_port: null
database_name: ------
database_user: root
database_password: -------
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: it
secret: ThisTokenIsNotSoSecretChangeIt
domain: -----
opentok_key: ----
opentok_secret: -----
Symfony2 have an important principe, all components are standalone.
For each piece of Symfony you'll use, if you can see an available configuration for it in your config.yml
, you must configure it. Especially if the configuration is empty.
As you can see in your config.yml
, parameters are called instead of raw expressions.
In fact, a parameters.yml
configuration file exists in the same directory (config/
). Your config.yml
call it automatically to get parameters it need. Set your e-mail configuration in your parameters.yml
(password, user, host ..), and then you can use it in your bundles, including FOSUserBundle and other external bundles.
An example of swiftmailer configuration for local postfix :
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: your@email.fr
mailer_password: yourpwd
All you need to do the trick is in the documentation. https://symfony.com/doc/current/cookbook/email/email.html
Have a good experience with Symfony !