public function smtpTest($verbose)
{
//Create a new SMTP instance
$smtp = new SMTP();
if ($verbose) {
// Enable connection-level debug output
$smtp->do_debug = 3;
}
try {
// connect to an SMTP server
if ($smtp->connect($this->host, $this->port)) {
// yay hello
if ($smtp->hello('localhost')) {
if ($smtp->authenticate($this->username, $this->password)) {
return true;
} else {
$data = [$this->host, $this->port, $this->smtpSecure, $this->username];
throw new Exception('Authentication failed (' . implode(',', $data) . '): ' . $smtp->getLastReply() . PHP_EOL . print_r($smtp->getError(), true));
}
} else {
throw new Exception('HELO failed: ' . $smtp->getLastReply());
}
} else {
throw new Exception('Connect failed');
}
} catch (Exception $e) {
$smtp->quit(true);
throw new \yii\base\Exception($e->getMessage());
}
}