user2269869
user2269869

Reputation: 191

How to send email with symfony2 over gmail?

I want to send an email using symfony with gmail. I mean both the sender and the receiver use gmail. I configured the config.yml as follows :

swiftmailer:
    transport: gmail
    encryption: ssl
    auth_mode:  login
    host:      smtp.gmail.com
    username:  username
    password:  pass
    spool:     { type: memory }






 $message = \Swift_Message::newInstance()
            ->setSubject('Hello Email')
            ->setFrom('[email protected]')
            ->setTo('[email protected]')
            ->setBody('hello')

Is this code correct?

An other note: when I added this code it worked

$form = $this->get('form.factory')->create(new xxxType(), array('key' => 'var'));

but with this it does not

$form = $this->createForm(new xxxType(),$entity);

Upvotes: 1

Views: 1159

Answers (2)

Sir l33tname
Sir l33tname

Reputation: 4330

I look at the documentation you just forgot

 $this->get('mailer')->send($message);

Source: http://symfony.com/doc/2.0/cookbook/email/email.html

Upvotes: 0

DRvanR
DRvanR

Reputation: 399

You are using the spool, which delays the sending of emails till you actually send the emails through the app/console command. The mails are kept in memory till then, as outlined in the docs linked before.

In order to send the email, you should stop using the spool, or send them manually.

Upvotes: 1

Related Questions