From a73d52dbc8fed3718a309216a33becfba0c36227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20B?= <1116761+fbonzon@users.noreply.github.com> Date: Fri, 27 Oct 2017 22:06:24 +0200 Subject: [PATCH] Improve error message for invalid address (#1213) Adds the address kind (From, Sender, ConfirmReadingTo) instead of word punyEncode which is internal to PHPMailer and not so helpful. Similarly, removes word addAnAddress (internal) but keeps only address kind (to, cc, bcc, Reply-To). --- src/PHPMailer.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/PHPMailer.php b/src/PHPMailer.php index 7641cd66a..449261510 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -962,7 +962,10 @@ protected function addOrEnqueueAnAddress($kind, $address, $name) $pos = strrpos($address, '@'); if (false === $pos) { // At-sign is missing. - $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address"; + $error_message = sprintf('%s (%s): %s', + $this->lang('invalid_address'), + $kind, + $address); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1010,7 +1013,9 @@ protected function addOrEnqueueAnAddress($kind, $address, $name) protected function addAnAddress($kind, $address, $name = '') { if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) { - $error_message = $this->lang('Invalid recipient kind: ') . $kind; + $error_message = sprintf('%s: %s', + $this->lang('Invalid recipient kind'), + $kind); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1020,7 +1025,10 @@ protected function addAnAddress($kind, $address, $name = '') return false; } if (!static::validateAddress($address)) { - $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address"; + $error_message = sprintf('%s (%s): %s', + $this->lang('invalid_address'), + $kind, + $address); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1126,7 +1134,9 @@ public function setFrom($address, $name = '', $auto = true) if (false === $pos or (!$this->has8bitChars(substr($address, ++$pos)) or !static::idnSupported()) and !static::validateAddress($address)) { - $error_message = $this->lang('invalid_address') . " (setFrom) $address"; + $error_message = sprintf('%s (From): %s', + $this->lang('invalid_address'), + $address); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1376,7 +1386,10 @@ public function preSend() } $this->$address_kind = $this->punyencodeAddress($this->$address_kind); if (!static::validateAddress($this->$address_kind)) { - $error_message = $this->lang('invalid_address') . ' (punyEncode) ' . $this->$address_kind; + $error_message = sprintf('%s (%s): %s', + $this->lang('invalid_address'), + $address_kind, + $this->$address_kind); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) {