Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SMTP extended error codes stored in $smtp->error
  • Loading branch information
heronman committed Nov 8, 2014
1 parent 85c7c6b commit 8d2961a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions class.smtp.php
Expand Up @@ -736,15 +736,27 @@ protected function sendCommand($command, $commandstring, $expect)
$this->client_send($commandstring . self::CRLF);

$this->last_reply = $this->get_lines();
$code = substr($this->last_reply, 0, 3);
// fetch SMTP code and possible error code explanation
if(preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $m)) {
$code = $m[1];
$code_ex = (count($m) > 2 ? $m[2] : null);
// cut off error code from every response line
$detail = preg_replace("/{$code}[ -]".($code_ex ? str_replace(".", "\\.", $code_ex)." " : "")."/m",
"", $this->last_reply);
} else { // fallback to simple parsing, if regex fails for some unexpected reason
$code = substr($this->last_reply, 0, 3);
$code_ex = null;
$detail = substr($this->last_reply, 4);
}

$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);

if (!in_array($code, (array)$expect)) {
$this->error = array(
'error' => "$command command failed",
'smtp_code' => $code,
'detail' => substr($this->last_reply, 4)
'smtp_code_ex' => $code_ex,
'detail' => $detail
);
$this->edebug(
'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
Expand Down

0 comments on commit 8d2961a

Please sign in to comment.