I built a droplet with Ubuntu with DigitalOcean and I'm trying to configure it to send emails with SMTP.
I know DigitalOcean blocks SMTP over IPv6 but not over IPv4 so I disabled IPv6 as this post says.
My script still doesn't work. I've tried with ports 25, 465 and 587. TLS and SSL.
I've installed sendmail
for Ubuntu 14.04 but not working.
This is my script:
<?php
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$to = $_GET['email'];
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'rafawins@gmail.com';
$mail->Password = '***';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('rafawins@gmail.com', 'Rafael');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'Subject';
$contents = ob_get_contents();
$mail->Body = "ao!";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
print_r(error_get_last());
?>
The error presented is:
SMTP connect() failed.
I'm interested in sending email using SMTP so ->isSMTP()
is required!
Where am I wrong?
Thank you very much.
EDIT:
doing: telnet smtp.gmail.com 587
I get:
Trying 74.125.133.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp
and doing: openssl s_client -connect smtp.gmail.com:465
I get an answer as well...
What's wrong?