Reputation: 293
I'm struggling with Symfony2 sending e-mails via SwiftMailer (working on localhost). I searched through documentation and different posts on stackoverflow for configurations and I managed to apply the configuration that won't make any errors but the messages are not coming to the inbox. Please take a quick look, maybe something small is missing:
parameters.yml
mailer_transport: gmail
mailer_host: ~
mailer_user: [email protected]
mailer_password: Testing1
config_dev.yml
swiftmailer:
transport: gmail
username: [email protected]
password: Testing1
in controller:
public function sendMail(Request $request)
{
$defaultData = array('name' => '', 'email' => '', 'subject' => '', 'message' => '');
$form = $this->createFormBuilder($defaultData)
->add('name', 'text')
->add('email', 'email')
->add('subject', 'text')
->add('message', 'textarea')
->add('submit', 'submit', array('label' => 'Send'))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$name = $form['name']->getData();
$email = $form['email']->getData();
$subject = $form['subject']->getData();
$message_mail = $form['message']->getData();
var_dump($name);
$mailer = $this->get('mailer');
$message = $mailer->createMessage()
->setSubject($subject)
->setFrom($email)
->setTo('[email protected]')
->setBody($message_mail);
$mailer->send($message);
}
}
Upvotes: 1
Views: 525
Reputation: 2512
Look in your gmail account, you can find a mail saying that there is some suspicious activity caused by your remote server, change the security settings and it should work.
To change this setting go to https://www.google.com/settings/security/lesssecureapps and turn on Access for less secure apps
Upvotes: 2
Reputation: 732
You should go on your gmail account activate remote access.
Also please verify that you dont have this in your configuration :
disable_delivery: true
During your dev phase, you can add this in your configuration :
swiftmailer: delivery_address: [email protected]
so all the mails will be sent to [email protected] whatever you set as TO.
Upvotes: 0