本文整理汇总了PHP中SMTP::getError方法的典型用法代码示例。如果您正苦于以下问题:PHP SMTP::getError方法的具体用法?PHP SMTP::getError怎么用?PHP SMTP::getError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMTP
的用法示例。
在下文中一共展示了SMTP::getError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setError
/**
* Add an error message to the error container.
* @access protected
* @param string $msg
* @return void
*/
protected function setError($msg)
{
$this->error_count++;
if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
$lasterror = $this->smtp->getError();
if (!empty($lasterror['error'])) {
$msg .= $this->lang('smtp_error') . $lasterror['error'];
if (!empty($lasterror['detail'])) {
$msg .= ' Detail: ' . $lasterror['detail'];
}
if (!empty($lasterror['smtp_code'])) {
$msg .= ' SMTP code: ' . $lasterror['smtp_code'];
}
if (!empty($lasterror['smtp_code_ex'])) {
$msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
}
}
}
$this->ErrorInfo = $msg;
}
示例2: testConnection
//.........这里部分代码省略.........
//try login to host
if ($auth_required == 'true') {
try {
if (preg_match('/^(.+):([0-9]+)$/', $srv, $hostinfo)) {
$server = $hostinfo[1];
$port = $hostinfo[2];
} else {
$server = $srv;
}
if (strtoupper($UseSecureCon) == 'TLS') {
$tls = 'tls';
}
if (strtoupper($UseSecureCon) == 'SSL') {
$tls = 'ssl';
}
$tls = strtoupper($UseSecureCon) == 'tls';
$ssl = strtoupper($UseSecureCon) == 'ssl';
$server = $_POST['server'];
if (strtoupper($UseSecureCon) == 'SSL') {
$resp = $smtp->Connect('ssl://' . $server, $port, $timeout);
} else {
$resp = $smtp->Connect($server, $port, $timeout);
}
if ($resp) {
$hello = $_SERVER['SERVER_NAME'];
$smtp->Hello($hello);
if (strtoupper($UseSecureCon) == 'TLS') {
$smtp->Hello($hello);
}
if ($smtp->Authenticate($user, $passwd)) {
$this->success = true;
} else {
if (strtoupper($UseSecureCon) == 'TLS') {
$this->success = true;
} else {
$this->success = false;
$smtpError = $smtp->getError();
$this->msg = $smtpError['error'];
// $this->msg = $smtp->error['error'];
}
}
} else {
$this->success = false;
$smtpError = $smtp->getError();
$this->msg = $smtpError['error'];
// $this->msg = $smtp->error['error'];
}
} catch (Exception $e) {
$this->success = false;
$this->msg = $e->getMessage();
}
} else {
$this->success = true;
$this->msg = 'No authentication required!';
}
break;
case 5:
if ($SendaTestMail == 'true') {
try {
$_POST['FROM_NAME'] = G::LoadTranslation('ID_MESS_TEST_BODY');
$_POST['FROM_EMAIL'] = $user;
$_POST['MESS_ENGINE'] = 'PHPMAILER';
$_POST['MESS_SERVER'] = $server;
$_POST['MESS_PORT'] = $port;
$_POST['MESS_ACCOUNT'] = $user;
$_POST['MESS_PASSWORD'] = $passwd;
$_POST['TO'] = $Mailto;
if ($auth_required == 'true') {
$_POST['SMTPAuth'] = true;
} else {
$_POST['SMTPAuth'] = false;
}
if (strtolower($_POST["UseSecureCon"]) != "no") {
$_POST["SMTPSecure"] = $_POST["UseSecureCon"];
}
/*
if ($_POST['UseSecureCon'] == 'ssl') {
$_POST['MESS_SERVER'] = 'ssl://'.$_POST['MESS_SERVER'];
}
*/
$resp = $this->sendTestMail();
if ($resp->status == '1') {
$this->success = true;
} else {
$this->success = false;
$smtpError = $smtp->getError();
$this->msg = $smtpError['error'];
// $this->msg = $smtp->error['error'];
}
} catch (Exception $e) {
$this->success = false;
$this->msg = $e->getMessage();
}
} else {
$this->success = true;
$this->msg = 'jump this step';
}
break;
}
}
示例3: checkSMTP
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;
}
示例4: smtpSend
/**
* Send mail via SMTP.
* Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
* Uses the PHPMailerSMTP class by default.
* @see PHPMailer::getSMTPInstance() to use a different class.
* @param string $header The message headers
* @param string $body The message body
* @throws phpmailerException
* @uses SMTP
* @access protected
* @return boolean
*/
protected function smtpSend($header, $body)
{
$bad_rcpt = array();
if (!$this->smtpConnect($this->SMTPOptions)) {
throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
if ('' == $this->Sender) {
$smtp_from = $this->From;
} else {
$smtp_from = $this->Sender;
}
if (!$this->smtp->mail($smtp_from)) {
$this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
}
// Attempt to send to all recipients
foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
foreach ($togroup as $to) {
if (!$this->smtp->recipient($to[0])) {
$error = $this->smtp->getError();
$bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
$isSent = false;
} else {
$isSent = true;
}
$this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
}
}
// Only send the DATA command if we have viable recipients
if (count($this->all_recipients) > count($bad_rcpt) and !$this->smtp->data($header . $body)) {
throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
}
if ($this->SMTPKeepAlive) {
$this->smtp->reset();
} else {
$this->smtp->quit();
$this->smtp->close();
}
//Create error message for any bad addresses
if (count($bad_rcpt) > 0) {
$errstr = '';
foreach ($bad_rcpt as $bad) {
$errstr .= $bad['to'] . ': ' . $bad['error'];
}
throw new phpmailerException($this->lang('recipients_failed') . $errstr, self::STOP_CONTINUE);
}
return true;
}
示例5: catch
$ssl = $SMTPSecure == 'ssl';
$resp = $smtp->Connect(($ssl ? 'ssl://' : '') . $host, $port, $timeout);
if ($resp) {
$hello = $_SERVER['SERVER_NAME'];
$smtp->Hello($hello);
if ($tls) {
if (!$smtp->StartTLS()) {
// problem with tls
}
//We must resend HELO after tls negotiation
$smtp->Hello($hello);
}
if ($smtp->Authenticate($user, $passwd)) {
print SUCCESSFUL . ',' . $smtp->status;
} else {
$smtpError = $smtp->getError();
print FAILED . ',' . $smtpError['error'];
// print (FAILED . ',' . $smtp->error['error']) ;
}
} else {
$smtpError = $smtp->getError();
print FAILED . ',' . $smtpError['error'];
// print (FAILED . ',' . $smtp->error['error']) ;
}
} catch (Exception $e) {
print FAILED . ',' . $e->getMessage();
}
} else {
print SUCCESSFUL . ', No authentication required!';
}
break;
示例6: testConnectionByStep
//.........这里部分代码省略.........
if (preg_match("/^(.+):([0-9]+)\$/", $srv, $hostinfo)) {
$server = $hostinfo[1];
$port = $hostinfo[2];
} else {
$server = $srv;
}
if (strtoupper($useSecureCon) == "TLS") {
$tls = "tls";
}
if (strtoupper($useSecureCon) == "SSL") {
$tls = "ssl";
}
$tls = strtoupper($useSecureCon) == "tls";
$ssl = strtoupper($useSecureCon) == "ssl";
$server = $arrayData["MESS_SERVER"];
if (strtoupper($useSecureCon) == "SSL") {
$resp = $smtp->Connect("ssl://" . $server, $port, $timeout);
} else {
$resp = $smtp->Connect($server, $port, $timeout);
}
if ($resp) {
$hello = $_SERVER["SERVER_NAME"];
$smtp->Hello($hello);
if (strtoupper($useSecureCon) == "TLS") {
$smtp->Hello($hello);
}
if ($smtp->Authenticate($user, $passwd)) {
$arrayResult["result"] = true;
} else {
if (strtoupper($useSecureCon) == "TLS") {
$arrayResult["result"] = true;
} else {
$arrayResult["result"] = false;
$smtpError = $smtp->getError();
$arrayResult["message"] = $smtpError["error"];
}
}
} else {
$arrayResult["result"] = false;
$smtpError = $smtp->getError();
$arrayResult["message"] = $smtpError["error"];
}
} catch (Exception $e) {
$arrayResult["result"] = false;
$arrayResult["message"] = $e->getMessage();
}
} else {
$arrayResult["result"] = true;
$arrayResult["message"] = "No authentication required!";
}
break;
case 5:
if ($sendTestMail == 1) {
try {
$arrayDataPhpMailer = array();
$eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\\.[0-9a-zA-Z]{2,3}\$/";
$arrayDataPhpMailer["FROM_EMAIL"] = $fromMail != "" && preg_match($eregMail, $fromMail) ? $fromMail : "";
$arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY");
$arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER";
$arrayDataPhpMailer["MESS_SERVER"] = $server;
$arrayDataPhpMailer["MESS_PORT"] = $port;
$arrayDataPhpMailer["MESS_ACCOUNT"] = $user;
$arrayDataPhpMailer["MESS_PASSWORD"] = $passwd;
$arrayDataPhpMailer["TO"] = $mailTo;
if ($auth_required == 1) {
$arrayDataPhpMailer["MESS_RAUTH"] = true;
示例7: setError
/**
* Add an error message to the error container.
*
* @param string $msg
*
* @return void
*/
protected function setError($msg)
{
$this->error_count++;
if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
$lasterror = $this->smtp->getError();
if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
$msg .= '<p>' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
}
}
$this->ErrorInfo = $msg;
}
示例8: sendResetMail
/**
* Send email using authenticated STMP with TLS
*/
function sendResetMail($to, $newpass)
{
$smtp = new SMTP();
//$smtp->setDebugLevel(4);
//$smtp->setDebugOutput("error_log");
$host = $this->config['smtp']['host'];
$port = $this->config['smtp']['port'];
// Connect
if (!$smtp->connect($host, $port)) {
return $smtp->getError();
}
// EHLO
if (!$smtp->hello("me")) {
return $smtp->getError();
}
// STARTTLS
if (!$smtp->startTLS()) {
return $smtp->getError();
}
// EHLO
if (!$smtp->hello("me")) {
return $smtp->getError();
}
// AUTH LOGIN
$username = $this->config['smtp']['username'];
$password = $this->config['smtp']['password'];
if (!$smtp->authenticate($username, $password)) {
return $smtp->getError();
}
// MAIL FROM
$from = $this->config['smtp']['from'];
if (!$smtp->mail($from)) {
return $smtp->getError();
}
// RCPT TO
if (!$smtp->recipient($to)) {
return $smtp->getError();
}
// DATA
$msg = str_replace("@@email@@", $to, str_replace("@@newpass@@", $newpass, $this->config['smtp']['msgtemplate']));
if (!$smtp->data($msg)) {
return $smtp->getError();
}
// QUIT
if (!$smtp->quit()) {
return $smtp->getError();
}
// Disconnect and close
$smtp->close();
return null;
}