flarum/framework · error · InvalidArgumentException

Both text and html views must be provided to send an email…

Error message

Both text and html views must be provided to send an email notification of type'.$blueprint::getType().'.

What it means

Flarum's NotificationMailer sends email notifications via Mailables. getEmailViews() requires the notification blueprint's getEmailViews() to return an array containing BOTH 'text' and 'html' keys; if either is missing it throws this InvalidArgumentException, since emails must ship a plain-text and an HTML variant.

Solutions

  1. Return both keys from getEmailViews(): ['text' => ..., 'html' => ...].
  2. Create the missing text (or html) view template and reference it.
  3. Double-check the blueprint's getType() naming shown in the message to find the offending class.
  4. For upgrades, align custom blueprints with the current Flarum Mailable blueprint interface requirements.

Example fix

// before
public function getEmailViews(): array
{
    return ['html' => 'emails.new-post'];
}
// after
public function getEmailViews(): array
{
    return ['html' => 'emails.new-post', 'text' => 'emails.new-post-text'];
}
Defensive patterns

Strategy: validation

Validate before calling

$views = $blueprint->getEmailViews();
if (!Arr::has($views, ['text', 'html'])) {
    throw new \LogicException(static::class.' must provide both text and html email views');
}

Type guard

function hasBothEmailViews(array $views): bool {
    return isset($views['text']) && isset($views['html']);
}

Try / catch

try {
    $mailer->send($notification, $users);
} catch (\InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'Both text and html views')) {
        Log::error('Notification blueprint missing email views', ['type' => $notification::getType()]);
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: A notification Blueprint class returns an array from getEmailViews() that lacks the 'html' or 'text' key (e.g. only ['html' => 'emails.notification'] or an empty array), and the notification is then sent via NotificationMailer::send().

Common situations: A custom extension notification blueprint forgot the text view; a view name typo/misplaced blade template removed a key; upgrading Flarum made the dual-view requirement stricter than an older blueprint implementation.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/6615f9ccb37853af. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Notification/NotificationMailer.php:88

    }

    /**
     * Retrieves the email views from the blueprint, and enforces that both a
     * plain text and HTML view are provided.
     *
     * @param MailableInterface&BlueprintInterface $blueprint
     * @return array{
     *     text: string,
     *     html: string
     * }
     */
    protected function getEmailViews(MailableInterface&BlueprintInterface $blueprint): array
    {
        $views = $blueprint->getEmailViews();

        // check that both text and html views are provided
        if (! Arr::has($views, ['text', 'html'])) {
            throw new \InvalidArgumentException('Both text and html views must be provided to send an email notification of type'.$blueprint::getType().'.');
        }

        return $views;
    }
}

View on GitHub (pinned to 4b939f6853)