function checkSMTP($smtp_server, $smtp_port = 25, $username, $password, $auth_enabled = false, $tls_enabled = true)
{
require_once "libs/phpmailer/class.smtp.php";
$smtp = new SMTP();
$smtp->Connect($smtp_server, $smtp_port);
if (!$smtp->Connected()) {
return array("ERROR" => "Failed to connect to server", "SMTP_ERROR" => $smtp->getError());
}
if (!$smtp->Hello()) {
return array("ERROR" => "Failed to send hello command", "SMTP_ERROR" => $smtp->getError());
}
if ($tls_enabled) {
if (!$smtp->StartTLS()) {
return array("ERROR" => "Failed to start TLS", "SMTP_ERROR" => $smtp->getError());
}
}
if ($auth_enabled) {
if (!$smtp->Authenticate($username, $password)) {
$error = $smtp->getError();
if (preg_match("/STARTTLS/", $error['smtp_msg'])) {
return array("ERROR" => "Authenticate Error, TLS must be activated", "SMTP_ERROR" => $smtp->getError());
} else {
return array("ERROR" => "Authenticate not accepted from server", "SMTP_ERROR" => $smtp->getError());
}
}
}
return true;
}