Skip to content

Instantly share code, notes, and snippets.

@BurakBoz
Last active May 18, 2022 23:47
Show Gist options
  • Save BurakBoz/6b370012b4e7c920db01cf4c9a7cc81a to your computer and use it in GitHub Desktop.
Save BurakBoz/6b370012b4e7c920db01cf4c9a7cc81a to your computer and use it in GitHub Desktop.
SMTP Test script

SMTP Test Script

This script checks if system firewall is blocking smtp ports.
For example: Godaddy hosting is usually blocks smtp ports.

Download script via shell

# download with wget
wget --no-check-certificate https://gist.githubusercontent.com/BurakBoz/6b370012b4e7c920db01cf4c9a7cc81a/raw/aa9fcdf29731460875aa15bf9b303eab47767d52/smtp-test.php -O smtp-test.php

# download with wget and run
wget --no-check-certificate https://gist.githubusercontent.com/BurakBoz/6b370012b4e7c920db01cf4c9a7cc81a/raw/aa9fcdf29731460875aa15bf9b303eab47767d52/smtp-test.php -O smtp-test.php && php smtp-test.php

# download with curl
curl https://gist.githubusercontent.com/BurakBoz/6b370012b4e7c920db01cf4c9a7cc81a/raw/aa9fcdf29731460875aa15bf9b303eab47767d52/smtp-test.php -o smtp-test.php

# download with curl and run
curl https://gist.githubusercontent.com/BurakBoz/6b370012b4e7c920db01cf4c9a7cc81a/raw/aa9fcdf29731460875aa15bf9b303eab47767d52/smtp-test.php -o smtp-test.php && php smtp-test.php

# Run tests via shell

php smtp-test.php

Run via web server

https://example.com/smtp-test.php
<?php
/**
* @Script smtp-test.php
* @Author Burak Boz
* @License: MIT
* @Description This script tests "SMTP ports are blocked by host firewall?"
* @WebSite https://github.com/BurakBoz
*/
@ignore_user_abort(false);
@ob_start();
@ob_implicit_flush(true);
@session_write_close();
@set_time_limit(200);
@ini_set('zlib.output_compression',0);
@ini_set('implicit_flush',1);
@ini_set('output_buffering', 0);
@header("Content-Type: text/plain;charset=utf8");
@header("Transfer-Encoding: chunked");
@header("Content-Encoding: none");
function sendBuffer($chunk)
{
if(PHP_SAPI === "cli")
{
echo trim($chunk) . PHP_EOL;
}
else
{
echo str_pad($chunk, 4097);
}
@flush();
@ob_flush();
}
sendBuffer("SMTP Server Connection Test Tool By Burak Boz\nfor more tools visit: https://github.com/BurakBoz" . PHP_EOL);
sendBuffer(str_pad("", 4096 * 6));
$hosts = [
"smtp.yandex.com",
"smtp.gmail.com",
"smtp.outlook.com",
"relay.dnsexit.com",
"relay-hosting.secureserver.net",
"dedrelay.secureserver.net",
"mail.authsmtp.com",
];
$ports = [
25,
465,
587,
80,
//443,
];
foreach ($hosts as $host)
{
foreach ($ports as $port)
{
$connection = @fsockopen($host, $port, $errno, $errstr, 5); // 5 second timeout for each port.
if (is_resource($connection))
{
sendBuffer(''.$host . ':' . $port . ' (' . getservbyport($port, 'tcp') . ') is open. ' . PHP_EOL);
fclose($connection);
}
else
{
sendBuffer(''.$host . ':' . $port . ' (' . getservbyport($port, 'tcp') . ') is not responding. ' . PHP_EOL);
}
}
}
echo PHP_EOL . "Tests are complete.";
flush();
ob_end_flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment