2

I had it totally working before, but I reinstalled ubuntu 13.10 on my server and now it doesnt work, my code is as follows:

require 'php/PHPMailer/PHPMailerAutoload.php';


$mail = new PHPMailer();

$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'mail@gmail.com';
$mail->Password = 'pass';
$mail->setFrom('mail@gmail.com', 'First Last');
$mail->addAddress('mail2@hotmail.com', 'Random person');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML('prueba');

//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

mail, mail2 and pass are just safewords, they are valid addresses and password.

OpenSSL is installed and working with a temporary cert.

Any ideas of why it doesnt work now after Ubuntu 13.10 reinstall?

Forgot to tell, the error Im getting now is:

SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) SMTP connect() failed. Mailer Error: SMTP connect() failed.

3 Answers3

1

I had the same problem. Turns out I didn't have sendmail installed on my server. I installed sendmail from fedora repo and restarted apache server and it connected.

Iman Akbari
  • 2,167
  • 26
  • 31
0

It's most likely a firewall setting in Ubuntu... Try using SSL instead or follow the instructions below for further investigation...

$mail->SMTPSecure = 'ssl';
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;

The problem means you are unable to connect to port 587 on server smtp.gmail.com . Verify this using telnet:

telnet smtp.gmail.com 587

(This works for me, so the server and port number are correct.)

Possible reasons for this to do not work from your location are:

  • Misconfigured proxy settings
  • A firewall at your location, which forbids to connect to this port number.

If the telnet command above can connect, then you can rule out a problem with the firewall. If it does not work, then it's most likely the firewall, which causes the problem.

Also, find out the port number which is used with your other connection method. Maybe that also works with TLS.

Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
0

I installed php-pear with some others packages and it was solved:

apt-get install php-pear pear install mail pear install Net_SMTP pear install Auth_SASL pear install mail_mime