ellite/Wallos · error · Exception

Invalid address ( )

Error message

Invalid address (%s): %s

What it means

preSend() validates the From, Sender, and ConfirmReadingTo properties after recipients are processed and throws 'Invalid address (%s): %s' (kind and value) when any of them fails validateAddress(). Thrown only with exceptions enabled; otherwise the error is recorded and preSend returns false, aborting send().

Solutions

  1. Use setFrom()/Sender setter APIs rather than assigning ->From/->Sender properties directly
  2. Validate each with PHPMailer::validateAddress() before assignment
  3. Remove or correctly set ConfirmReadingTo if read receipts are not needed
  4. Catch the exception around send() and log which address kind failed (the message includes the kind)

Example fix

// before
$mail->From = $_GET['from']; // bypasses validation, fails in preSend
// after
$from = $_GET['from'];
if (PHPMailer::validateAddress($from)) {
    $mail->setFrom($from);
} else {
    throw new InvalidArgumentException('Invalid From address');
}
Defensive patterns

Strategy: validation

Validate before calling

foreach (['From'=>$from,'Sender'=>$sender,'ConfirmReadingTo'=>$confirm] as $k=>$a) { if ($a !== '' && !PHPMailer::validateAddress($a)) { throw new InvalidArgumentException("Invalid $k: $a"); } }

Try / catch

try { $mail->send(); } catch (PHPMailer\PHPMailer\Exception $e) { // message contains the address kind that failed $log->error($e->getMessage()); throw $e; }

Prevention

When it happens

Trigger: setFrom()/setSender()/ConfirmReadingTo set to an address failing validation; properties set directly ($mail->From = 'bad') bypassing setFrom()'s checks; addresses corrupted by later code before send().

Common situations: Setting $mail->From directly from config without validation, Sender path ('/usr/sbin/sendmail'-style values or invalid return-path) misconfigured, confirm-reading-to (read receipt) address copied from unvalidated user input.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of ellite/Wallos@52820e87ca (2026-09-13). Data as JSON: /api/errors/846784e2d81aba44. Report an issue: GitHub.

Appendix: source

Thrown at libs/PHPMailer/PHPMailer.php:1593

                    $this->{$address_kind} = '';
                    continue;
                }
                $this->{$address_kind} = trim($this->{$address_kind});
                if (empty($this->{$address_kind})) {
                    continue;
                }
                $this->{$address_kind} = $this->punyencodeAddress($this->{$address_kind});
                if (!static::validateAddress($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) {
                        throw new Exception($error_message);
                    }

                    return false;
                }
            }

            //Set whether the message is multipart/alternative
            if ($this->alternativeExists()) {
                $this->ContentType = static::CONTENT_TYPE_MULTIPART_ALTERNATIVE;
            }

            $this->setMessageType();
            //Refuse to send an empty message unless we are specifically allowing it
            if (!$this->AllowEmpty && empty($this->Body)) {
                throw new Exception($this->lang('empty_message'), self::STOP_CRITICAL);
            }

            //Trim subject consistently

View on GitHub (pinned to 52820e87ca)