{"record":{"id":"611f994e9461b35f","repo":"ellite/Wallos","slug":"this-lang-file-access-path","errorCode":null,"errorMessage":"$this->lang('file_access') . $path","messagePattern":"\\$this->lang\\('file_access'\\) \\. \\$path","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":3228,"sourceCode":"     * @param string $name        Overrides the attachment name\n     * @param string $encoding    File encoding (see $Encoding)\n     * @param string $type        MIME type, e.g. `image/jpeg`; determined automatically from $path if not specified\n     * @param string $disposition Disposition to use\n     *\n     * @throws Exception\n     *\n     * @return bool\n     */\n    public function addAttachment(\n        $path,\n        $name = '',\n        $encoding = self::ENCODING_BASE64,\n        $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,","sourceCodeStart":3210,"sourceCodeEnd":3246,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L3210-L3246","documentation":"addAttachment() throws lang('file_access') followed by the path when static::fileIsAccessible() reports the file cannot be read (missing file or unreadable permissions). The exception severity is STOP_CONTINUE, so with exceptions disabled PHPMailer records the error and continues; with exceptions enabled it propagates.","triggerScenarios":"Calling $mail->addAttachment('/path/to/file.pdf') where the file does not exist, is a directory, or the PHP process lacks read permission.","commonSituations":"Relative paths resolved against the CWD instead of the script directory, files uploaded then moved/deleted before send(), wrong permissions after deployment, or path typos in config.","solutions":["Verify the file exists and is readable with is_file() and is_readable() before addAttachment()","Use absolute paths (e.g. __DIR__ . '/files/report.pdf') instead of relative ones","Fix filesystem permissions so the web-server/PHP user can read the file","Check isError()/errorInfo() after addAttachment if you run with exceptions disabled"],"exampleFix":"// before\n$mail->addAttachment('uploads/report.pdf');\n// after\n$path = __DIR__ . '/uploads/report.pdf';\nif (!is_file($path) || !is_readable($path)) { throw new RuntimeException(\"Attachment not readable: $path\"); }\n$mail->addAttachment($path, 'report.pdf');","handlingStrategy":"validation","validationCode":"$path = __DIR__ . '/uploads/report.pdf';\nif (!is_file($path) || !is_readable($path)) { throw new RuntimeException(\"Attachment missing or unreadable: $path\"); }\n$mail->addAttachment($path, 'report.pdf');","typeGuard":"function readableFilePath($p): ?string { return is_string($p) && is_file($p) && is_readable($p) ? $p : null; }","tryCatchPattern":"try { $ok = $mail->addAttachment($path); if (!$ok) throw new RuntimeException($mail->ErrorInfo); } catch (PHPMailer\\PHPMailer\\Exception $e) { error_log('Attachment failed: ' . $e->getMessage()); }","preventionTips":["Resolve attachment paths to absolute paths at upload time","Check is_readable() for every attachment before adding","After addAttachment, inspect $mail->isError() when exceptions are disabled","Keep uploaded files on durable storage until after send()"],"tags":["phpmailer","attachment","file-access"],"backgroundTag":"file-not-found","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"}