Using SwiftMailer with smtp.gmail.com fails on sending mail
I am attempting to use the gmail as an smtp server in my php application,
which uses the SwiftMailer library, but I am encountering errors when
trying to send the email.
I get the following exception :
Expected response code 220 but got code "", with message ""
in "\classes\Swift\Transport\AbstractSmtpTransport.php"
This problem was similar to the problem found in this thread trying to
send mail using swift mailer, gmail smtp, php
However, I have had no luck adding the ssl parameter to my code
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl" )
->setUsername('myemail@gmail.com')
->setPassword('mypassword');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('MySubject')
->setFrom(array('myemail@gmail.com' => 'MyName'))
->setTo(array('YourEmail@gmail.com' => 'YourName'))
->setBody('BodyText');
$numSent = $mailer->send($message);
printf("Sent %d messages\n", $numSent);
I have checked my hosting site (freezoy.com) configuration paramaters and
found ssl allowed and openssl enabled. I have also tried with TLS on port
587, and ensure that the username and password are valid and correct.
I'm somewhat new to the web development game so I don't know all the
tricks of the trade, and would greatly appreciate some input!
No comments:
Post a Comment