The issue is that your email is being received as plain text instead of HTML. That's why the Markdown and HTML tags are being shown as raw text, rather than being rendered as styled content and buttons.
Why does this happen?
- Laravel's Markdown emails are designed to be sent as HTML.
- If the email client or the sending configuration treats the email as plain text, the HTML will not be rendered.
How to fix it:
-
Make sure you are using the correct mail driver.
- Some drivers (like
logormailgunin test mode) may not render HTML. - In your
.envfile, useMAIL_MAILER=smtp(or another driver that supports HTML).
- Some drivers (like
-
Do not use the
textmethod in your Mailable.- You are already using the
markdownmethod, which is correct.
- You are already using the
-
Check your email client.
- Some email clients (or webmail previews) show only the plain text version.
- Try opening the email in a different client or check the "View as HTML" option.
-
Make sure your Markdown template is correct.
- Your template looks fine, but ensure you are not escaping the HTML somewhere else.
-
Test with a simple HTML email.
- Try sending a basic HTML email to confirm your setup:
Mail::raw('<b>Hello World</b>', function ($message) { $message->to('[email protected]')->subject('Test HTML'); });If this shows as HTML, your setup is correct.
Summary:
- The problem is not in your code, but in how the email is being sent or viewed.
- Ensure you're using an HTML-supporting mail driver and viewing the email in an HTML-capable client.
Extra tip:
If you want to force HTML, you can use the html method in your Mailable for testing:
public function build()
{
return $this->markdown('emails.new_answer_notification');
}
But with Laravel 9+ and the new Mailable structure, your code is already correct.
In short:
Check your mail driver and email client. Your code for sending Markdown emails is correct.