3

I want to know if the connection to Gmail's SMTP was successful or not.

I'm using:

$fp = fsockopen("smtp.gmail.com", 587, $errno, $errstr, 30);
if ($fp) {
    echo "Its Ok";
}
else
{
    echo "No";
}

But it didn't work.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
Jhonny Afonso
  • 291
  • 4
  • 14
  • Maybe this can help: http://stackoverflow.com/questions/16169295/how-to-check-smtp-server-is-working-or-not-using-php – AkiEru Sep 04 '15 at 03:22

1 Answers1

0

Your code works for me.
Did you check your registered stream socket transports in phpinfo() as below?

Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls, tlsv1.0, tlsv1.1, tlsv1.2

I think the problem may result from php version(My is 5.6.8). Please refers to the php explanation:

The ssl:// and tls:// transports (available only when openssl support is compiled into PHP) are extensions of the tcp:// transport which include SSL encryption. Since PHP 4.3.0 OpenSSL support must be statically compiled into PHP, since PHP 5.0.0 it may be compiled as a module or statically.

Jerry Chen
  • 31
  • 1
  • 5