Here is my code:
setUs
I have managed to get this working without the SSL, here is how:
$transport = Swift_SmtpTransport::newInstance('tls://smtp.gmail.com', 465)
->setUsername('contact@columbussoft.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($subject)
->setFrom(array($emailTo=>$name))
->setTo(array($emailTo=>'Neo Nosrati'))
->addPart($body,'text/plain')
->setReturnPath('other@columbussoft.com');
I'm using the "Messages Swift Mailer" bundle in Laravel 3 and having the same issue. After some testing, in my case, the solution was to set the same email address that I used in the SMTP authentication on the "from" parameter.
I was trying to use a different address and that was triggering the "swiftmailer expected response code 220 but got code with message" error.
Hope that helps.
Swift SmtpTransport - Code (send a email)
The SMTP of GMAIL is: smtp.googlemail.com
The Full Code:
<?php
$pEmailGmail = 'xxxx@gmail.com';
$pPasswordGmail = '********';
$pFromName = 'MundialSYS.com'; //display name
$pTo = 'xxxxxx@xxxx.xxx'; //destination email
$pSubjetc = "Hello MundialSYS"; //the subjetc
$pBody = '<html><body><p>Hello MundialSYS</p></html></body>'; //body html
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
->setUsername($pEmailGmail)
->setPassword($pPasswordGmail);
$mMailer = Swift_Mailer::newInstance($transport);
$mEmail = Swift_Message::newInstance();
$mEmail->setSubject($pSubjetc);
$mEmail->setTo($pTo);
$mEmail->setFrom(array($pEmailGmail => $pFromName));
$mEmail->setBody($pBody, 'text/html'); //body html
if($mMailer->send($mEmail) == 1){
echo 'send ok';
}
else {
echo 'send error';
}
?>
there is missing the ssl parameter, it should be something like that
Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
Tested and work fine
I cannot be sure, but I think that Gmail's port is 587 using TLS, which is not SSL, but a newer version of it. You should check into that, because I think you are placing the wrong construction code.
Best of luck!
For google apps, in addition to setting to port 465 and ssl as recommended in the accepted answer, you may have to enable allow less secure apps setting, as per https://stackoverflow.com/a/25238515/947370