I have following code that uses Swift mailer
to send mail via PHP
<?php
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465, 'ssl')
->setUsername('my.email@mydomain.com')
->setPassword('emailpassword');
$message = Swift_Message::newInstance()
->setSubject("This is test subject")
->setFrom(array("sender.email@gmail.com"))
->setTo(array("recipient.email@gmail.com"))
->setBody("This is test mail body","text/html");
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
This works pretty well, the recipient gets an email. But however, if I change username and password in transport to that of gmail like this -
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465, 'ssl')
->setUsername('sender.email@gmail.com') //this is the change, using gmail
->setPassword('senderpassword'); //this is the change
Then this doesnot work.
Can anybody tell me where I m doing wrong? what configuration I m missing?
P.S. I checked SPAM folder as well