{"record":{"id":"e345a4d650011a3c","repo":"ellite/Wallos","slug":"invalid-address-to-cc-bcc-s","errorCode":null,"errorMessage":"Invalid address (to/cc/bcc): %s","messagePattern":"Invalid address \\(to/cc/bcc\\): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":1181,"sourceCode":"            $this->setError($error_message);\n            $this->edebug($error_message);\n            if ($this->exceptions) {\n                throw new Exception($error_message);\n            }\n\n            return false;\n        }\n        if (!static::validateAddress($address)) {\n            $error_message = sprintf(\n                '%s (%s): %s',\n                $this->lang('invalid_address'),\n                $kind,\n                $address\n            );\n            $this->setError($error_message);\n            $this->edebug($error_message);\n            if ($this->exceptions) {\n                throw new Exception($error_message);\n            }\n\n            return false;\n        }\n        if ('Reply-To' !== $kind) {\n            if (!array_key_exists(strtolower($address), $this->all_recipients)) {\n                $this->{$kind}[] = [$address, $name];\n                $this->all_recipients[strtolower($address)] = true;\n\n                return true;\n            }\n        } elseif (!array_key_exists(strtolower($address), $this->ReplyTo)) {\n            $this->ReplyTo[strtolower($address)] = [$address, $name];\n\n            return true;\n        }\n\n        return false;","sourceCodeStart":1163,"sourceCodeEnd":1199,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L1163-L1199","documentation":"addAnAddress throws 'Invalid address (to/cc/bcc): %s' when the recipient address fails static::validateAddress() (default: PCRE-based check, or an injected validator). The kind is echoed in the message. Like other address errors it only throws when $this->exceptions is true, otherwise it records the error and returns false.","triggerScenarios":"$mail->addAddress($addr)/addCC/addBCC where $addr is empty, lacks a domain, contains illegal characters, or otherwise fails validateAddress(); also when queued recipients are replayed in preSend and fail validation.","commonSituations":"Form input not validated server-side, placeholder strings left in config ('user@example' with no TLD is actually valid to the regex but 'foo@' is not), comma-separated lists passed as a single address, or a custom validator injected via PHPMailer::$validator rejecting legitimate addresses.","solutions":["Validate with PHPMailer::validateAddress($email) before adding and surface a friendly error to the user","Split comma/semicolon-separated recipient strings with a parser (or use RFC 822 parsing) before addAddress","Strip whitespace, newlines, and angle brackets before passing the address","Check/replace a custom $validator override that may be too strict","Ensure ext-intl/idn_to_ascii works if using unicode domains, or pre-convert to punycode"],"exampleFix":"// before\n$mail->addAddress($_POST['recipients']); // 'a@x.com, b@y.com'\n// after\nforeach (array_filter(array_map('trim', explode(',', $_POST['recipients']))) as $rcpt) {\n    if (!PHPMailer::validateAddress($rcpt)) {\n        continue; // or collect and report\n    }\n    $mail->addAddress($rcpt);\n}","handlingStrategy":"validation","validationCode":"foreach ($recipients as $r) { if (!PHPMailer::validateAddress(trim($r))) { throw new InvalidArgumentException(\"Invalid recipient: $r\"); } }","typeGuard":"function isValidEmail(mixed $v): bool { return is_string($v) && PHPMailer::validateAddress(trim($v)); }","tryCatchPattern":"try { $mail->send(); } catch (PHPMailer\\PHPMailer\\Exception $e) { if (str_contains($e->getMessage(), 'Invalid address')) { log_invalid_recipient($e->getMessage()); } throw $e; }","preventionTips":["Validate at the boundary (forms/APIs) with PHPMailer::validateAddress or FILTER_VALIDATE_EMAIL","Reject comma-separated strings; parse into individual addresses","Sanitize by trimming and stripping whitespace/newlines/angle brackets","Review any custom $validator override"],"tags":["php","phpmailer","email","address-validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd","analyzedAt":"2026-09-13T14:09:30.873Z","contentChangedAt":"2026-09-13T14:09:30.873Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}