Hi,
I am trying to use Swift Mailer to send emails from PHP using Gmail's SMTP server.
I've checked some examples, but when I try to send emails I get this message:
Connection to the given MTA failed. The Connection Interface said: Unable to find the socket transport "tls" - did you forget to enable it when you configured PHP?
Not sure what the error is trying to imply by asking if I've configured PHP to use TLS (I think it is a generic error message gone pearshaped). Anyone has used this program and can help please?
Here is the code:
require('Swift.php');
require('Swift/Swift_SMTP_Connection.php');
//The mailer will now establish a connection with the server
$mailer = new Swift(new Swift_SMTP_Connection('smtp.gmail.com', 587, SWIFT_TLS));
//If anything goes wrong you can see what happened in the logs
if ($mailer->isConnected()) //Optional
{
//You can call authenticate() anywhere before calling send()
if ($mailer->authenticate('javierh@gmail.com', 'javierh'))
{
//Sends a simple email
$mailer->send(
'"Joe Bloggs" <javierh@xyz.com>',
'"Your name" <you@yourdomain.com>',
'Some Subject',
"Hello Joe it's only me!"
);
}
else echo "Didn't authenticate to server";
//Closes cleanly... works without this but it's not as polite.
$mailer->close();
}
else echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br />
Log: <pre>".print_r($mailer->transactions, 1)."</pre>";
Many thanks