{"record":{"id":"23381058ded81570","repo":"cakephp/cakephp","slug":"transfer-encoding-not-available-can-be-s","errorCode":null,"errorMessage":"Transfer encoding not available. Can be : %s.","messagePattern":"Transfer encoding not available\\. Can be : (.+?)\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Mailer/Message.php","lineNumber":643,"sourceCode":"     */\n    public function getHeaderCharset(): string\n    {\n        return $this->headerCharset ?: $this->charset;\n    }\n\n    /**\n     * TransferEncoding setter.\n     *\n     * @param string|null $encoding Encoding set.\n     * @return $this\n     * @throws \\InvalidArgumentException\n     */\n    public function setTransferEncoding(?string $encoding)\n    {\n        if ($encoding !== null) {\n            $encoding = strtolower($encoding);\n            if (!in_array($encoding, $this->transferEncodingAvailable, true)) {\n                throw new InvalidArgumentException(\n                    sprintf(\n                        'Transfer encoding not available. Can be : %s.',\n                        implode(', ', $this->transferEncodingAvailable),\n                    ),\n                );\n            }\n        }\n\n        $this->transferEncoding = $encoding;\n\n        return $this;\n    }\n\n    /**\n     * TransferEncoding getter.\n     *\n     * @return string|null Encoding\n     */","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Mailer/Message.php#L625-L661","documentation":"Message::setTransferEncoding() validates the given encoding against Message::$transferEncodingAvailable (e.g. 7bit, 8bit, quoted-printable, base64) and throws InvalidArgumentException for anything outside that list. Transfer encoding controls how the email body is encoded in transit.","triggerScenarios":"setTransferEncoding('gzip'), setTransferEncoding('Base64') casing is fine (lowercased) but unknown values like 'binary-enc' or empty-but-non-null strings throw.","commonSituations":"Confusing Content-Transfer-Encoding values with character encodings ('utf-8'); copying encoding names from another mail library; passing user-supplied encoding config from a settings file.","solutions":["Use one of the supported values: '7bit', '8bit', 'quoted-printable', or 'base64'.","Pass null to reset transfer encoding to default instead of an invalid value.","If the value comes from config, whitelist/validate it before passing."],"exampleFix":"// before\n$message->setTransferEncoding('utf-8');\n// after\n$message->setTransferEncoding('base64');","handlingStrategy":"validation","validationCode":"$allowed = ['7bit', '8bit', 'quoted-printable', 'base64'];\nif ($encoding !== null && !in_array(strtolower($encoding), $allowed, true)) {\n    throw new \\InvalidArgumentException(\"Unsupported transfer encoding: $encoding\");\n}","typeGuard":"function isValidTransferEncoding(?string $encoding): bool {\n    return $encoding === null || in_array(strtolower($encoding), ['7bit', '8bit', 'quoted-printable', 'base64'], true);\n}","tryCatchPattern":"try {\n    $message->setTransferEncoding($encoding);\n} catch (\\InvalidArgumentException $e) {\n    $message->setTransferEncoding(null); // default\n}","preventionTips":["Only pass the four documented encodings","Never confuse transfer encoding with charset (utf-8)","Validate config-driven encodings against a whitelist"],"tags":["email","encoding","invalid-enum"],"backgroundTag":"invalid-enum-value","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"}