Skip to content

Commit

Permalink
Improve error message for invalid address (PHPMailer#1213)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
fbonzon authored and Synchro committed Oct 27, 2017
1 parent 5af110e commit a73d52d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a73d52d

Please sign in to comment.