So I have spent days on trying to send e-mails using swiftmailer by php and I am using localhost xampp server v3.2.1, which the PHP version is 5.4.31 and my swiftmailer is I believe v5.3
Here is the PHP file :
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
->setUsername('username@gmail.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('username@gmail.com'))
->setTo(array('recipient@gmail.com'))
->setBody('Hello World')
;
$result = $mailer->send($message);
if (!$mailer->send($message,$failures)) {
echo "Failures:";
print_r($failures);
} else {
echo "sent";
}
The page just returned blank and there are no e-mail sent or received.Please tell if there is anything I should configure before getting this to work or am I missing an important line of code or something.
Thank you in advance.
I keep trying and once I got an input in my error log which is :
[15-Oct-2014 16:33:49 Europe/Berlin] PHP Fatal error: Uncaught exception 'Swift_TransportException' with message 'Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 fn2sm17247597pdb.75 - gsmtp
"' in C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php:386
Stack trace:
#0 C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(281): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('535-5.7.8 Usern...', Array)
#1 C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\EsmtpTransport.php(245): Swift_Transport_AbstractSmtpTransport->executeCommand('RSET
', Array, Array)
#2 C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\Esmtp\Auth\XOAuth2Authenticator.php(56): Swift_Transport_EsmtpTransport->executeCommand('RSET
', Array)
#3 C:\xampp\htdocs\1\vendor\swiftmailer\swiftma in C:\xampp\htdocs\1\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php on line 386
It finally managed to send e-mails, what I had to do is change the security setting in my gmail account and disabled the security protection and now it sends e-mail perfectly
Try to set your transporter like this:
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465);
You can also check for exceptions:
try {
$mailer = Swift_Mailer::newInstance($transport);
} catch(Swift_TransportException $exception) {
var_dump($exception);
}
"535-5.7.8 Username and Password not accepted." means that third parties are not allowed access to your account. You need to grant them access to 3rd parties by uppdating your google account at:
Under "login" find the phrase "allow less secure apps access" and change this to "ALLOW.