{"record":{"id":"b7db2bcbb6a448d7","repo":"ellite/Wallos","slug":"this-lang-encoding-encoding","errorCode":null,"errorMessage":"$this->lang('encoding') . $encoding","messagePattern":"\\$this->lang\\('encoding'\\) \\. \\$encoding","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":3241,"sourceCode":"        $type = '',\n        $disposition = 'attachment'\n    ) {\n        try {\n            if (!static::fileIsAccessible($path)) {\n                throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);\n            }\n\n            //If a MIME type is not specified, try to work it out from the file name\n            if ('' === $type) {\n                $type = static::filenameToType($path);\n            }\n\n            $filename = (string) static::mb_pathinfo($path, PATHINFO_BASENAME);\n            if ('' === $name) {\n                $name = $filename;\n            }\n            if (!$this->validateEncoding($encoding)) {\n                throw new Exception($this->lang('encoding') . $encoding);\n            }\n\n            $this->attachment[] = [\n                0 => $path,\n                1 => $filename,\n                2 => $name,\n                3 => $encoding,\n                4 => $type,\n                5 => false, //isStringAttachment\n                6 => $disposition,\n                7 => $name,\n            ];\n        } catch (Exception $exc) {\n            $this->setError($exc->getMessage());\n            $this->edebug($exc->getMessage());\n            if ($this->exceptions) {\n                throw $exc;\n            }","sourceCodeStart":3223,"sourceCodeEnd":3259,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L3223-L3259","documentation":"addAttachment() throws lang('encoding') plus the given encoding string when validateEncoding() rejects the $encoding argument. Only the constants PHPMailer supports (7bit, 8bit, base64, binary, quoted-printable) are accepted for attachments.","triggerScenarios":"Passing an unsupported encoding such as 'base 64', 'BASE64', 'utf-8', or a typo to addAttachment($path, $name, $encoding).","commonSituations":"Developers confusing content encoding with charset and passing 'utf-8' or 'iso-8859-1'; hand-typed 'base64' vs the constant is fine, but misspellings like 'base-64' fail.","solutions":["Use the class constants: PHPMailer::ENCODING_BASE64, ENCODING_7BIT, ENCODING_8BIT, ENCODING_BINARY, ENCODING_QUOTED_PRINTABLE","Remove the explicit encoding argument and rely on the default (base64)","Check for typos/case: the accepted values are lowercase exact strings"],"exampleFix":"// before\n$mail->addAttachment($path, 'report.pdf', 'base-64');\n// after\n$mail->addAttachment($path, 'report.pdf', PHPMailer::ENCODING_BASE64);","handlingStrategy":"type-guard","validationCode":"$allowed = [PHPMailer::ENCODING_7BIT, PHPMailer::ENCODING_8BIT, PHPMailer::ENCODING_BASE64, PHPMailer::ENCODING_BINARY, PHPMailer::ENCODING_QUOTED_PRINTABLE];\nif (!in_array($encoding, $allowed, true)) { throw new InvalidArgumentException(\"Unsupported attachment encoding: $encoding\"); }","typeGuard":"function isValidMailEncoding($e): bool { return is_string($e) && in_array($e, ['7bit','8bit','base64','binary','quoted-printable'], true); }","tryCatchPattern":"try { $mail->addAttachment($path, $name, $encoding); } catch (PHPMailer\\PHPMailer\\Exception $e) { if (str_contains($e->getMessage(), 'encoding')) { $mail->addAttachment($path, $name, PHPMailer::ENCODING_BASE64); } else { throw $e; } }","preventionTips":["Always pass the PHPMailer::ENCODING_* constants, never raw strings","Never pass charset values (utf-8) where an encoding is expected","Centralize attachment calls in a wrapper that validates the encoding constant"],"tags":["phpmailer","attachment","encoding","invalid-argument"],"backgroundTag":"invalid-enum-value","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"}