ellite/Wallos · error · Exception

( )

Error message

%s (%s): %s

What it means

PHPMailer throws this when an address cannot be added to the queue via addOrEnqueueAnAddress (the dispatcher behind addAddress/addCC/addBCC/addReplyTo). The message is built as '%s (%s): %s' with the localized error, the recipient kind, and the address. It only throws when the $exceptions property is true; otherwise setError/edebug record it and the method returns false.

Solutions

  1. Enable exceptions properly (new PHPMailer(true)) and wrap send()/addAddress() in try-catch to see the full message
  2. Validate the address with PHPMailer::validateAddress($email) before calling addAddress/addCC/addBCC/addReplyTo
  3. Trim user input and reject empty strings; never pass arrays where a string is expected
  4. Ensure the ext-intl extension is available if using IDN (unicode) addresses, or use ASCII (punycode) addresses
  5. Check you are not passing a name into the address parameter by mistake (addAddress($addr, $name) signature)

Example fix

// before
$mail->addAddress($userInputEmail);
// after
if (PHPMailer::validateAddress($userInputEmail)) {
    $mail->addAddress(trim($userInputEmail));
} else {
    throw new InvalidArgumentException('Invalid recipient: ' . $userInputEmail);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!PHPMailer::validateAddress($email)) { throw new InvalidArgumentException("Invalid email: $email"); }

Type guard

function isEmailString(mixed $v): bool { return is_string($v) && filter_var(trim($v), FILTER_VALIDATE_EMAIL) !== false; }

Try / catch

try { $mail->addAddress($email, $name); } catch (PHPMailer\PHPMailer\Exception $e) { $this->logger->error('Recipient rejected: ' . $e->getMessage()); throw new InvalidRecipientException($email, $e); }

Prevention

When it happens

Trigger: Calling addAddress/addCC/addBCC/addReplyTo with an invalid kind or an address that fails static::validateAddress() while $mail->Exceptions (exceptions) is enabled; also when enqueued addresses later fail punyencodeAddress conversion.

Common situations: Passing empty strings or user-supplied input without validation, addresses containing commas or newlines from form input, internationalized addresses on PHP builds without idn_to_ascii (INTL_IDNA_VARIANT issues), or PHPMailer 6.x behavior change where addAnAddress was split into addOrEnqueueAnAddress.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at libs/PHPMailer/PHPMailer.php:1094

    protected function addOrEnqueueAnAddress($kind, $address, $name)
    {
        $pos = false;
        if ($address !== null) {
            $address = trim($address);
            $pos = strrpos($address, '@');
        }
        if (false === $pos) {
            //At-sign is missing.
            $error_message = sprintf(
                '%s (%s): %s',
                $this->lang('invalid_address'),
                $kind,
                $address
            );
            $this->setError($error_message);
            $this->edebug($error_message);
            if ($this->exceptions) {
                throw new Exception($error_message);
            }

            return false;
        }
        if ($name !== null && is_string($name)) {
            $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
        } else {
            $name = '';
        }
        $params = [$kind, $address, $name];
        //Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
        //Domain is assumed to be whatever is after the last @ symbol in the address
        if (static::idnSupported() && $this->has8bitChars(substr($address, ++$pos))) {
            if ('Reply-To' !== $kind) {
                if (!array_key_exists($address, $this->RecipientsQueue)) {
                    $this->RecipientsQueue[$address] = $params;

                    return true;

View on GitHub (pinned to 52820e87ca)