ellite/Wallos · error · Exception

%s: %s

Error message

%s: %s

What it means

In addAnAddress, PHPMailer throws '%s: %s' when the $kind parameter is not one of the allowed recipient kinds (to, cc, bcc, Reply-To, From, ConfirmReadingTo). The message carries the localized 'Invalid recipient kind' text and the bad kind. Only thrown when $this->exceptions is true.

Solutions

  1. Use the public API addAddress/addCC/addBCC/addReplyTo instead of calling addAnAddress directly
  2. Use the exact kind strings PHPMailer expects ('to','cc','bcc','Reply-To','From','ConfirmReadingTo') if you must call it in a subclass
  3. Inspect your RecipientsQueue entries if the error appears during send() — the queued params array was corrupted
  4. Upgrade to a current PHPMailer 6.x release where kind handling is centralized

Example fix

// before
$mail->addAnAddress('To', $email); // wrong case, invalid kind
// after
$mail->addAddress($email);
Defensive patterns

Strategy: type-guard

Validate before calling

$allowed = ['to','cc','bcc','Reply-To','From','ConfirmReadingTo']; if (!in_array($kind, $allowed, true)) { throw new InvalidArgumentException("Bad kind: $kind"); }

Type guard

function isValidRecipientKind(mixed $k): bool { return is_string($k) && in_array($k, ['to','cc','bcc','Reply-To','From','ConfirmReadingTo'], true); }

Try / catch

try { $mail->send(); } catch (PHPMailer\PHPMailer\Exception $e) { if (str_contains($e->getMessage(), 'Invalid recipient kind')) { /* inspect queued params */ } throw $e; }

Prevention

When it happens

Trigger: Internal/indirect calls to addAnAddress (e.g., via call_user_func_array from preSend replaying RecipientsQueue/ReplyToQueue) receiving a corrupted or misspelled kind string; or user code calling the protected addAnAddress directly with an invalid first argument.

Common situations: Subclassing PHPMailer and calling addAnAddress('To', ...) with wrong case ('To' vs 'to'), version drift between PHPMailer 5.x ('to') and 6.x kinds, or queue params array whose [0] element was overwritten.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at libs/PHPMailer/PHPMailer.php:1166

     * @param string $address The email address to send, resp. to reply to
     * @param string $name
     *
     * @throws Exception
     *
     * @return bool true on success, false if address already used or invalid in some way
     */
    protected function addAnAddress($kind, $address, $name = '')
    {
        if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) {
            $error_message = sprintf(
                '%s: %s',
                $this->lang('Invalid recipient kind'),
                $kind
            );
            $this->setError($error_message);
            $this->edebug($error_message);
            if ($this->exceptions) {
                throw new Exception($error_message);
            }

            return false;
        }
        if (!static::validateAddress($address)) {
            $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;

View on GitHub (pinned to 52820e87ca)