{"record":{"id":"2ad0953fe1d81af3","repo":"cakephp/cakephp","slug":"invalid-format-to-message-id-the-text-should-be-something","errorCode":null,"errorMessage":"Invalid format to Message-ID. The text should be something like \"<uuid@server.com>\"","messagePattern":"Invalid format to Message-ID\\. The text should be something like \"<uuid@server\\.com>\"","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Mailer/Message.php","lineNumber":1077,"sourceCode":"\n        return [$format];\n    }\n\n    /**\n     * Sets message ID.\n     *\n     * @param string|bool $message True to generate a new Message-ID, False to ignore (not send in email),\n     *   String to set as Message-ID.\n     * @return $this\n     * @throws \\InvalidArgumentException\n     */\n    public function setMessageId(string|bool $message)\n    {\n        if (is_bool($message)) {\n            $this->messageId = $message;\n        } else {\n            if (!preg_match('/^\\<.+@.+\\>$/', $message)) {\n                throw new InvalidArgumentException(\n                    'Invalid format to Message-ID. The text should be something like \"<uuid@server.com>\"',\n                );\n            }\n            $this->messageId = $message;\n        }\n\n        return $this;\n    }\n\n    /**\n     * Gets message ID.\n     *\n     * @return string|bool\n     */\n    public function getMessageId(): string|bool\n    {\n        return $this->messageId;\n    }","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Mailer/Message.php#L1059-L1095","documentation":"Message::setMessageId() accepts either bool or a string; a string must match /^<.+@.+>$/ i.e. angle-bracketed Message-ID like '<uuid@server.com>'. Anything else throws InvalidArgumentException. This ensures a standards-compliant RFC Message-ID header.","triggerScenarios":"setMessageId('uuid@server.com') (missing < >), setMessageId('my-id'), or passing a bare UUID. Called during testSend/testSendHeadersStripCrlf flows.","commonSituations":"Developers generating a UUID and forgetting to wrap it in < >; copying Message-ID values without brackets from email clients; building ids from variables containing spaces/newlines.","solutions":["Wrap the id in angle brackets: setMessageId('<' . $uuid . '@example.com>')","Pass true/false if you only want default/auto behavior","Validate against the regex /^<.+@.+>$/ before calling"],"exampleFix":"// before\n$message->setMessageId($uuid . '@server.com');\n// after\n$message->setMessageId('<' . $uuid . '@server.com>');","handlingStrategy":"validation","validationCode":"if (!(is_bool($id) || (is_string($id) && preg_match('/^<.+@.+>$/', $id)))) {\n    throw new \\InvalidArgumentException('Message-ID must be bool or \"<local@domain>\"');\n}\n$message->setMessageId($id);","typeGuard":"function isValidMessageId(mixed $id): bool {\n    return is_bool($id) || (is_string($id) && preg_match('/^<.+@.+>$/', $id) === 1);\n}","tryCatchPattern":"try {\n    $message->setMessageId($id);\n} catch (\\InvalidArgumentException $e) {\n    $message->setMessageId(true); // fall back to auto-generated ID\n}","preventionTips":["Always build ids as '<' . $uuid . '@yourdomain>'","Copy Message-IDs with brackets included","Trim generated ids to avoid stray whitespace/newlines"],"tags":["cakephp","email","message-id","format-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}