Skip to content

Instantly share code, notes, and snippets.

@hungtrinh
Created December 30, 2014 10:09
Show Gist options
  • Save hungtrinh/417df6d01f1cec5ccadb to your computer and use it in GitHub Desktop.
Save hungtrinh/417df6d01f1cec5ccadb to your computer and use it in GitHub Desktop.
PHP check SMTP authentication without sending email
set_include_path(implode(PATH_SEPARATOR, array(
'/Users/apple/www/zend_compact/library', //point to Zend lib directory
get_include_path()
)));
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$host = 'smtp.gmail.com';
$port = 465;
$config = array(
'auth' => 'login',
'ssl' => 'ssl',
'username' => 'yourgmail.com',
'password' => 'testmail'
);
class SmtpAuthentication extends Zend_Mail_Protocol_Smtp_Auth_Login {
protected $_authMessage = null;
public function getAuthenMessage() {
return $this->_authMessage;
}
public function isAuthenSuccess() {
try {
$this->connect();
$this->helo();
return $this->_auth;
}
catch(Zend_Mail_Protocol_Exception $e) {
$this->_authMessage = $e->getMessage();
}
return false;
}
};
$smtp = new SmtpAuthentication($host, $port, $config);
var_dump($smtp->isAuthenSuccess()); // succes or failed
var_dump($smtp->getAuthenMessage()); // cause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment