{"record":{"id":"122109b414dae5e1","repo":"flarum/framework","slug":"you-must-enter-a-valid-email","errorCode":null,"errorMessage":"You must enter a valid email.","messagePattern":"You must enter a valid email\\.","errorType":"validation","errorClass":"ValidationFailed","httpStatus":null,"severity":"error","filePath":"framework/core/src/Install/AdminUser.php","lineNumber":44,"sourceCode":"    {\n        return $this->username;\n    }\n\n    public function getAttributes(): array\n    {\n        return [\n            'username' => $this->username,\n            'email' => $this->email,\n            'password' => (new BcryptHasher)->make($this->password),\n            'joined_at' => Carbon::now(),\n            'is_email_confirmed' => 1,\n        ];\n    }\n\n    private function validate(): void\n    {\n        if (! filter_var($this->email, FILTER_VALIDATE_EMAIL)) {\n            throw new ValidationFailed('You must enter a valid email.');\n        }\n\n        if (! $this->username || preg_match('/[^a-z0-9_-]/i', $this->username)) {\n            throw new ValidationFailed('Username can only contain letters, numbers, underscores, and dashes.');\n        }\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":52,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Install/AdminUser.php#L26-L52","documentation":"During installation, AdminUser::validate() checks the admin email with filter_var(FILTER_VALIDATE_EMAIL). An email that fails that check causes ValidationFailed('You must enter a valid email.'). The constructor runs this validation immediately, so an invalid email aborts object creation.","triggerScenarios":"Constructing AdminUser with an empty, malformed, or whitespace-containing email during web or console installation.","commonSituations":"Installer form submitted with a blank or mistyped email (missing @, spaces, trailing punctuation); automated installs with placeholder emails like 'admin' or 'changeme'.","solutions":["Provide a syntactically valid email (must contain a local part, @, and domain) to the installer","Pre-validate the email field in the installer UI before submission","Trim whitespace from input before constructing AdminUser"],"exampleFix":"// before\nnew AdminUser('admin', 'not-an-email', 'secret');\n// after\n$email = filter_var(trim($email), FILTER_VALIDATE_EMAIL);\nif ($email === false) { /* re-prompt */ }\nnew AdminUser('admin', $email, 'secret');","handlingStrategy":"validation","validationCode":"if (filter_var(trim($email), FILTER_VALIDATE_EMAIL) === false) {\n    throw new ValidationFailed('Please enter a valid email address.');\n}","typeGuard":"function isValidEmail(?string $email): bool { return $email !== null && filter_var(trim($email), FILTER_VALIDATE_EMAIL) !== false; }","tryCatchPattern":"try {\n    $admin = new AdminUser($username, $email, $password);\n} catch (ValidationFailed $e) {\n    $form->addError('email', $e->getMessage());\n}","preventionTips":["Validate email client-side (type=email + server-side filter_var) before install","Trim whitespace from all installer inputs","Never allow blank or placeholder emails in automated installs"],"tags":["validation","email","installation","admin-user"],"backgroundTag":"invalid-argument-format","analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}