{"record":{"id":"3701608f2197284b","repo":"ellite/Wallos","slug":"invalid-address-from-s","errorCode":null,"errorMessage":"Invalid address (From): %s","messagePattern":"Invalid address \\(From\\): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/PHPMailer/PHPMailer.php","lineNumber":1324,"sourceCode":"    {\n        $address = trim((string)$address);\n        $name = trim(preg_replace('/[\\r\\n]+/', '', $name)); //Strip breaks and trim\n        //Don't validate now addresses with IDN. Will be done in send().\n        $pos = strrpos($address, '@');\n        if (\n            (false === $pos)\n            || ((!$this->has8bitChars(substr($address, ++$pos)) || !static::idnSupported())\n            && !static::validateAddress($address))\n        ) {\n            $error_message = sprintf(\n                '%s (From): %s',\n                $this->lang('invalid_address'),\n                $address\n            );\n            $this->setError($error_message);\n            $this->edebug($error_message);\n            if ($this->exceptions) {\n                throw new Exception($error_message);\n            }\n\n            return false;\n        }\n        $this->From = $address;\n        $this->FromName = $name;\n        if ($auto && empty($this->Sender)) {\n            $this->Sender = $address;\n        }\n\n        return true;\n    }\n\n    /**\n     * Return the Message-ID header of the last email.\n     * Technically this is the value from the last time the headers were created,\n     * but it's also the message ID of the last sent message except in\n     * pathological cases.","sourceCodeStart":1306,"sourceCodeEnd":1342,"githubUrl":"https://github.com/ellite/Wallos/blob/52820e87ca5a6e105fdbb7f1c0c681bc0cfee2fd/libs/PHPMailer/PHPMailer.php#L1306-L1342","documentation":"setFrom() throws 'Invalid address (From): %s' when the From address fails static::validateAddress(). The From address becomes the envelope sender and the From header, so PHPMailer refuses invalid values early. Thrown only when $this->exceptions is true; otherwise returns false after setError.","triggerScenarios":"$mail->setFrom($addr) or setFrom($addr, $name, $auto) with an empty or malformed $addr; $auto=true also attempts to derive a From address from the server (SERVER_NAME) and validate it, which can fail on CLI or odd hostnames.","commonSituations":"Hardcoded placeholder From addresses ('noreply@localhost') rejected by a strict validator, missing From entirely while $auto default relies on SERVER_NAME being unset in CLI scripts, corporate domains with unusual but valid characters rejected by the default regex.","solutions":["Always call setFrom() with a validated, explicit address: if (PHPMailer::validateAddress($from)) $mail->setFrom($from);","If relying on auto-detection ($auto=true), set an explicit From in CLI/cron contexts where SERVER_NAME is undefined","Check validator strictness: PHPMailer::$validator can be set to 'pcre', 'php', 'html5', or 'eai', or a callable","Verify the address has no trailing punctuation, spaces, or embedded newlines from config files"],"exampleFix":"// before\n$mail->setFrom($config['from_email'] ?? ''); // empty fails\n// after\n$from = $config['from_email'] ?? '';\nif (!PHPMailer::validateAddress($from)) {\n    throw new RuntimeException('Sender address not configured');\n}\n$mail->setFrom($from, $config['from_name'] ?? '');","handlingStrategy":"validation","validationCode":"if (!PHPMailer::validateAddress($from)) { throw new InvalidArgumentException(\"Invalid From: $from\"); } $mail->setFrom($from, $fromName);","typeGuard":null,"tryCatchPattern":"try { $mail->send(); } catch (PHPMailer\\PHPMailer\\Exception $e) { if (str_contains($e->getMessage(), 'From')) { /* fix sender config */ } throw $e; }","preventionTips":["Always set an explicit From via setFrom(); never rely on auto-detection in CLI","Keep sender addresses in validated configuration","Use setFrom(), not direct property assignment","Choose an appropriate $validator ('pcre','php','html5','eai') for your address formats"],"tags":["php","phpmailer","email","from-address","address-validation"],"backgroundTag":"invalid-argument-format","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"}