fugitive
fugitive

Reputation: 367

PHPMailer unable to connect ot server

PHPmailer works just fine on my localhost, but when I moved it to the production, I am getting this kind of error:

Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ) 2016-09-28 12:58:01 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Connection timed out) 2016-09-28 12:58:01 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2016-09-28 12:58:01 SMTP connect() failed.

I've tried both TLS and SSL, updating ports accordingly. Also I've run a quick nmap scan, and it show that ports are open properly, so that's not an issue

PORT    STATE    SERVICE
25/tcp  filtered smtp
443/tcp open     https
465/tcp open     smtps
587/tcp open     submission

This is a snippet from my app:

public function __construct() {
    parent::__construct();

    $this->isSMTP();
    $this->SMTPAuth = true;
    $this->SMTPSecure = 'tls';
    $this->Host = MAIL_HOST;
    $this->Username = MAIL_USERNAME;
    $this->Password = MAIL_PASSWORD;
    $this->From = 'myemail';
    $this->FromName = 'Name';
    $this->addEmbeddedImage('../public/img/message_logo.png', 'logo');
    $this->isHTML(true);
    $this->Port = 587;
    $this->Subject = "SUBJECT";
    $this->SMTPDebug = MAIL_SMTP_DEBUG;
}

Anyone know what to check next?

Upvotes: 1

Views: 10799

Answers (2)

Mike
Mike

Reputation: 1

Don't know about GMail, but with Office 365 I needed to disable the SSL-check.

$this -> SMTPOptions = [ 'ssl' => [ 'verify_peer' => false ] ];

Edit: you might want to make sure you trust the host before disabling the SSL peer verification.

Upvotes: 0

Synchro
Synchro

Reputation: 37700

This is a very common problem, usually caused by outbound SMTP blocking by your ISP, e.g. GoDaddy does this. What's that nmap scan of? gmail?

By the error message contents, I'd also guess you're using an old version of PHPMailer.

Diagnosing this kind of problem is covered in the PHPMailer troubleshooting guide.

Upvotes: 2

Related Questions