0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 10:02:14 +02:00

add details from SMTP::getError() to STARTTLS exceptions

This commit is contained in:
Michael Newton 2021-10-11 11:43:27 -04:00
parent cbfe93b75a
commit 7b4e8cdf92

View File

@ -2143,7 +2143,8 @@ class PHPMailer
} }
if ($tls) { if ($tls) {
if (!$this->smtp->startTLS()) { if (!$this->smtp->startTLS()) {
throw new Exception($this->lang('connect_host')); $message = $this->getSmtpErrorMessage('connect_host');
throw new Exception($message);
} }
//We must resend EHLO after TLS negotiation //We must resend EHLO after TLS negotiation
$this->smtp->hello($hello); $this->smtp->hello($hello);
@ -4110,6 +4111,26 @@ class PHPMailer
return $key; return $key;
} }
/**
* Build an error message starting with a generic one and adding details if possible.
*
* @param string $base_key
* @return string
*/
private function getSmtpErrorMessage($base_key)
{
$message = $this->lang($base_key);
$error = $this->smtp->getError();
if (!empty($error['error'])) {
$message .= ' ' . $error['error'];
if (!empty($error['detail'])) {
$message .= ' ' . $error['detail'];
}
}
return $message;
}
/** /**
* Check if an error occurred. * Check if an error occurred.
* *