01 logo

Tutorial on how to send an email using Laravel Markdown Template?

Learn about Markdown templates with the help of the Laravel Mail Example. Here’s a tutorial for you on how to send an email using Laravel Markdown Template?

By Rachael GreyPublished 3 years ago 3 min read
Like

Email has become the most important part of our lives and also companies. This tutorial will show you how to use the Laravel mail example to send an email using a Markdown template. It's no big deal to implement Markdown templates. This tutorial will help you to send emails using Markdown.

After the user enters their title and email location and clicks the "Submit" button, you will send an email to the email address they entered. Please log in with this email address, where you can check your email.

Step-by-step guidelines

Step 1. Laravel project creation

composer create-project laravel/laravel --prefer-dist BacancyEmail

Step 2: Configure options:

Here we set the mail settings. To do this, we will add Gmail SMTP settings, such as title, identification, etc. (Allow two-step confirmation and access control for less secure applications in Gmail). We will apply our .env file and add the settings specified below.

MAIL_MAILER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

[email protected]

MAIL_PASSWORD= (third party app password <a href="https://support.google.com/accounts/answer/185833?hl=en" target="_blank">click hear</a>)

MAIL_ENCRYPTION=tls

[email protected]

MAIL_FROM_NAME="${APP_NAME}"

Step 3. Use Markdown to compose an email:

In this part, we will use Markdown to create a mailable class. A unique mailable class that will allow us to utilize Laravel events. It also grants the ability to reuse them anyplace in the app. First, we formulate the Mailable class by running the following Craft command:

php artisan make:mail BacancyMail --markdown=emails.BacancyMail

Running the preceding command will create two files:

app / Mail / BacancyMail.

phpresources / views/emails / BacancyMail.blade.php

Open the BacancyMail.php file in our application folder and draft the following code.

Step 4: mail controller has to be designed

In this step, we will design a controller method. We will create MailController as the brand-new controller. Run the subsequent command to generate MailController.

php artisan make:controller MailController

app/http/Controllers/MailController

Step 5: structure should be uncomplicated

An app that accepts user names and email addresses has to be created in this step. Open Resources/Views/welcome.blade.php and add the following code.

<body class="antialiased">

<div

class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center py-4 sm:pt-0">

<div class="max-w-6xl mx-auto sm:px-6 lg:px-8">

@if (session('status'))

<div class="alert alert-success">

{{ session('status') }}

</div>

@endif

<div class="flex justify-center pt-8 sm:justify-start sm:pt-0">

<h1>Bacancy Technology Mail Sending Tutorials</h1>

</div>

<div class="mt-8 bg-white dark:bg-gray-800 overflow-hidden shadow sm:rounded-lg">

<div class="grid grid-cols-1 md:grid-cols-2">

<div class="p-6">

<div class="ml-12">

<form action="{{route('send.email')}}" method="POST">

@csrf

<h6>Enter Name</h6>

<input style="background:DarkGrey; width:500px; height:35px" type="text" name="name" value="" />

<br>

<h6>Enter Email </h6>

<input style="background:DarkGrey; width:500px; height:35px" type="email" name="email" id="email">

<br><br><br>

<input class="btn btn-dark btn-block" type="submit" value="submit" name="submit">

</form>

</div>

</div>

</div>

</div>

</div>

</div>

</body>

Step 6: the body of the email has to be composed:

A file labeled as BacancyMail.blade.php for the email template was created in step 3. This record is handy for writing configuration code. We will add the below-mentioned code:

@component('mail::message')

<h1>Hello {{$body['name']}},</h1>

<p>The email is a sample email for Laravel Tutorial: How to Send an Email using Laravel 8 from @component('mail::button', ['url' => $body['url_a']])

Bacancy Technology

@endcomponent</p>

<p>Visit @component('mail::button', ['url' => $body['url_b']])

Laravel Tutorials

@endcomponent and learn more about the Laravel framework.</p>

Happy coding!<br>

Thanks,<br>

{{ config('app.name') }}<br>

Laravel Team.

@endcomponent

Step 7: Determine the route:

In this step, we will create a route. We will build one for our inquiry email. For this, we apply our network path file; go to the web.php file, and determine the subsequent path.

Route::get('/', function () {

return view('welcome');

});

Route::post('/sendBacancyMail',[MailController::class,'sendMail'])->name('send.email');

Step 8: Operate the project:

Now, we are finally finished without the Laravel mail example. Run the project with the following code:

php artisan serve.

To conclude, this was a laravel mail example using Markdown templates in Laravel 8. The Laravel mail example is straightforward. So let's copy the Github repository and use the code. It will help you. Visit the Laravel tutorial to learn more about Laravel.

apps
Like

About the Creator

Rachael Grey

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.