{"record":{"id":"bb678eb258df6f91","repo":"ellite/Wallos","slug":"this-lang-signing-openssl-error-string","errorCode":null,"errorMessage":"$this->lang('signing') . openssl_error_string()","messagePattern":"\\$this->lang\\('signing'\\) \\. openssl_error_string\\(\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":3083,"sourceCode":"                        'file://' . realpath($this->sign_cert_file),\n                        ['file://' . realpath($this->sign_key_file), $this->sign_key_pass],\n                        [],\n                        PKCS7_DETACHED,\n                        $this->sign_extracerts_file\n                    );\n                }\n\n                @unlink($file);\n                if ($sign) {\n                    $body = file_get_contents($signed);\n                    @unlink($signed);\n                    //The message returned by openssl contains both headers and body, so need to split them up\n                    $parts = explode(\"\\n\\n\", $body, 2);\n                    $this->MIMEHeader .= $parts[0] . static::$LE . static::$LE;\n                    $body = $parts[1];\n                } else {\n                    @unlink($signed);\n                    throw new Exception($this->lang('signing') . openssl_error_string());\n                }\n            } catch (Exception $exc) {\n                $body = '';\n                if ($this->exceptions) {\n                    throw $exc;\n                }\n            }\n        }\n\n        return $body;\n    }\n\n    /**\n     * Get the boundaries that this message will use\n     * @return array\n     */\n    public function getBoundaries()\n    {","sourceCodeStart":3065,"sourceCodeEnd":3101,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L3065-L3101","documentation":"PHPMailer throws lang('signing') plus the openssl error string when openssl_pkcs7_sign() fails during S/MIME message signing in createBody(). The message body is discarded and the openssl diagnostic is appended to identify the cause.","triggerScenarios":"sign_key_file and sign_key_cert are set, PKCS7_TEXT is defined, but openssl_pkcs7_sign() returns false — typically due to unreadable/corrupt key or certificate files, a key/cert mismatch, or a wrong passphrase.","commonSituations":"Expired or malformed PEM certificates, certificate and private key not matching, relative paths that don't resolve under the web server user, or an unencrypted key file passed where a passphrase-protected one is required (or vice versa).","solutions":["Verify the private key and certificate match: compare openssl x509 -noout -modulus and openssl rsa -noout -modulus outputs","Check key/cert file paths are absolute and readable by the PHP process user","Confirm the PEM files are valid: openssl rsa -in key.pem -check and openssl x509 -in cert.pem -noout -text","Read the appended openssl_error_string() message in the exception for the exact OpenSSL failure reason"],"exampleFix":"// before\n$mail->sign('key.pem', 'cert.pem'); // relative paths, unreadable by www-data\n// after\n$mail->sign('/etc/ssl/private/mail.key', '/etc/ssl/certs/mail.crt');\nchmod 600 /etc/ssl/private/mail.key; chown www-data /etc/ssl/private/mail.key","handlingStrategy":"validation","validationCode":"$key = openssl_pkey_get_private('file:///etc/ssl/private/mail.key', $pass);\nif (!$key) throw new RuntimeException('Signing key invalid: ' . openssl_error_string());\nopenssl_x509_parse('file:///etc/ssl/certs/mail.crt') ?: throw new RuntimeException('Signing cert invalid');","typeGuard":"function signingFilesValid(string $key, string $cert): bool { return is_readable($key) && is_readable($cert) && (bool) openssl_x509_parse('file://' . $cert) && (bool) openssl_pkey_get_private('file://' . $key); }","tryCatchPattern":"try { $mail->send(); } catch (PHPMailer\\PHPMailer\\Exception $e) { if (str_contains($e->getMessage(), 'Signing failed') || str_contains($e->getMessage(), 'signing')) { error_log('S/MIME signing failed: ' . $e->getMessage()); } throw $e; }","preventionTips":["Validate key/cert pair match (modulus compare) before configuring signing","Use absolute, permission-checked paths readable by the PHP user","Log openssl_error_string() whenever signing setup changes","Renew certificates before expiry and re-verify after rotation"],"tags":["phpmailer","openssl","smime","signing"],"backgroundTag":"api-request-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"}