afeef
afeef

Reputation: 4696

Email is not Receiving through Swift Mailer Symfony2

controller code

 public function EmaiAction(Request $request)
 {
    $mailer = $this->get('mailer');

    $logger = new \Swift_Plugins_Loggers_ArrayLogger();
    $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));


    $message = \Swift_Message::newInstance()
    ->setSubject('Hello')
    ->setFrom('[email protected]')
    ->setTo('***@gmail.com')
    ->setBody('This is a test email.');

    if ($this->get('mailer')->send($message)) {
    echo '[SWIFTMAILER] sent email to ';
    } else {
    echo '[SWIFTMAILER] not sending email: ' . $mailer->dump();
    }    

die("email send");

}

output

   [SWIFTMAILER] sent email to

config.yml

swiftmailer:
disable_delivery:  true
transport: smtp
encryption: ssl
port:   465
auth_mode: login
host:      smtp.gmail.com
username:  ***@gmail.com
password:  passwrd
delivery_address: [email protected]

Upvotes: 1

Views: 490

Answers (2)

MrSpider
MrSpider

Reputation: 62

disable_delivery:  true

This disables mail sending for development (See Docs)

Additionally try the swiftmailer config like this

swiftmailer:
    transport: gmail
    username:  ***@gmail.com
    password:  passwrd

Upvotes: 1

Arcv
Arcv

Reputation: 279

$message = \Swift_Message::newInstance()
->setSubject('Hello')
->setFrom('[email protected]')
->setTo('***@gmail.com')
->setBody('This is a test email.');
$this->get('mailer')->send($message);

Upvotes: 0

Related Questions