Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Gmail smtp authentication #827

Closed
janko216 opened this issue Nov 15, 2016 · 2 comments
Closed

Gmail smtp authentication #827

janko216 opened this issue Nov 15, 2016 · 2 comments

Comments

@janko216
Copy link

janko216 commented Nov 15, 2016

I'm using a code (see below) to send emails via Gmail smtp servers. Today it suddenly stopped working... Does anybody know about any changes in Google's settings? What's wrong? Thank you for comments!

require_once 'swift/lib/swift_required.php';

// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('xxxx') // Your Gmail Username
->setPassword('xxxx'); // Your Gmail Password

// Mailer
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('xxxxxx')
->setFrom(array('xxxx' => 'xxxx')) // can be $_POST['email'] etc...
->setTo(array($to => $data['jmeno'])) // your email / multiple supported.
->setBody($message, 'text/html');

// Send the message
if ($mailer->send($message)) {
$url = $_SERVER['HTTP_REFERER']; // right back to the referrer page from where you came.
echo '';
} else {
echo 'I am sure, your configuration are not correct. :(';
}

@moderndeveloperllc
Copy link

@janko216 - I don't use GMail, but I would perhaps try to remove the ssl:// from the host and set as ssl for the third parameter in newInstance(). Also try tls as the third parameter. Make sure that your phpinfo() has a Registered Stream Socket Transports readout that includes ssl and tls. Updating to the latest OpenSSL would also be wise as Google is starting to get picky about connecting via old encryption suites.

@janko216
Copy link
Author

Thank you for comments. It was caused by some troubles on Google servers :) Now, it works great (the same code).

makasim pushed a commit to formapro-forks/swiftmailer that referenced this issue Jul 26, 2017
@fabpot fabpot closed this as completed Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants