{"record":{"id":"3b49c38860658935","repo":"ellite/Wallos","slug":"this-lang-file-open-path","errorCode":null,"errorMessage":"$this->lang('file_open') . $path","messagePattern":"\\$this->lang\\('file_open'\\) \\. \\$path","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":3402,"sourceCode":"        $mime[] = sprintf('--%s--%s', $boundary, static::$LE);\n\n        return implode('', $mime);\n    }\n\n    /**\n     * Encode a file attachment in requested format.\n     * Returns an empty string on failure.\n     *\n     * @param string $path     The full path to the file\n     * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'\n     *\n     * @return string\n     */\n    protected function encodeFile($path, $encoding = self::ENCODING_BASE64)\n    {\n        try {\n            if (!static::fileIsAccessible($path)) {\n                throw new Exception($this->lang('file_open') . $path, self::STOP_CONTINUE);\n            }\n            $file_buffer = file_get_contents($path);\n            if (false === $file_buffer) {\n                throw new Exception($this->lang('file_open') . $path, self::STOP_CONTINUE);\n            }\n            $file_buffer = $this->encodeString($file_buffer, $encoding);\n\n            return $file_buffer;\n        } catch (Exception $exc) {\n            $this->setError($exc->getMessage());\n            $this->edebug($exc->getMessage());\n            if ($this->exceptions) {\n                throw $exc;\n            }\n\n            return '';\n        }\n    }","sourceCodeStart":3384,"sourceCodeEnd":3420,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L3384-L3420","documentation":"encodeFile() throws lang('file_open') plus the path when fileIsAccessible() fails just before reading the attachment during message assembly (attachAll -> encodeFile). This is a re-check at send time — the file became inaccessible after addAttachment() accepted it. Severity STOP_CONTINUE means send() aborts the message but the error may be collected rather than thrown if exceptions are off.","triggerScenarios":"File exists when addAttachment() is called but is deleted, moved, or made unreadable before send(); also mismatched permissions after a job queue delay between add and send.","commonSituations":"Temp files (e.g. tmpfile uploads) cleaned up before send(), files removed by cron between validation and transmission, long-running workers holding stale paths.","solutions":["Re-verify the file still exists and is readable immediately before send()","Keep temporary attachment files alive until after send() returns (use copy() to a durable location)","Ensure the sending process user retains read permission on the path","Check $mail->ErrorInfo for the exact path that failed"],"exampleFix":"// before\n$mail->addAttachment($tmpPath);\n// later\n$mail->send(); // tmp already deleted\n// after\n$mail->addAttachment($tmpPath);\nif (!is_readable($tmpPath)) { copy($tmpPath, $perm = tempnam(sys_get_temp_dir(), 'att')); $mail->clearAttachments(); $mail->addAttachment($perm); }\n$mail->send();","handlingStrategy":"validation","validationCode":"foreach ($paths as $p) { if (!is_file($p) || !is_readable($p)) { throw new RuntimeException(\"Attachment disappeared: $p\"); } }\n$mail->send();","typeGuard":"function ensureReadableAtSend(string $p): string { if (!is_file($p) || !is_readable($p)) { throw new RuntimeException(\"File unreadable at send time: $p\"); } return $p; }","tryCatchPattern":"try { $mail->send(); } catch (PHPMailer\\PHPMailer\\Exception $e) { if (str_contains($e->getMessage(), 'Could not access file') || str_contains($e->getMessage(), 'file_open')) { error_log('Attachment unreadable at send: ' . $e->getMessage()); } throw $e; }","preventionTips":["Copy temp attachments to a stable location and delete only after send()","In queue-based systems, re-verify attachments in the send worker","Keep attachment lifetime longer than the add-to-send interval","Monitor $mail->ErrorInfo which contains the offending path"],"tags":["phpmailer","attachment","file-open","race-condition"],"backgroundTag":"file-open-failed","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"}