Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gegeriyadi/031b69dc174358de6d134d6cf32a56cf to your computer and use it in GitHub Desktop.
Save gegeriyadi/031b69dc174358de6d134d6cf32a56cf to your computer and use it in GitHub Desktop.

Simple script to check outgoing mail port is open or not

<?php

$host = 'smtp.sendgrid.net';
$ports = array(25, 587, 465);

foreach ($ports as $port)
{
    $connection = @fsockopen($host, $port);

    if (is_resource($connection))
    {
        echo '<h2>' . $host . ':' . $port . ' ' . '(' . getservbyport($port, 'tcp') . ') is open.</h2>' . "\n";

        fclose($connection);
    }

    else
    {
        echo '<h2>' . $host . ':' . $port . ' is not responding.</h2>' . "\n";
    }
}

?>

don't forget to change $host to your SMTP server host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment