How to send email in laravel using markdown

How to send email in laravel using markdown

In this post we will give you information about How to send email in laravel using markdown. Hear we will give you detail about How to send email in laravel using markdownAnd how to use it also give you demo for it if it is necessary.

Laravelcode share with you how to send email in laravel using laravel markdown functionality. it is very easy and very simple. so we are write here and share with you very easy way how to send email using email markdown in laravel.

In laravel 5.4 send email functionality something change. in laravel 5.4 provided email markdown functionality for send email

Markdown mailable messages allow you to take advantage of the pre-built templates and components of mail notifications in your mailables. Since the messages are written in Markdown, Laravel is able to render beautiful, responsive HTML templates for the messages while also automatically generating a plain-text counterpart.

Here we are share with you email send in laravel example when user register then after send one confirmation link on use email address

Step : 1 Create new laravel application

Here, we are create new one laravel project by using collowing command


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

Step : 2 Create route for send mail


Route::get('sendemail', '[email protected]')->name('sendemail');

Step : 4 Create SendEmailController

Now, we are need to create SendEmailController.php file in app/Http/Controllers folder


<?php
namespace AppHttpControllers;

use AppMailTestMail;
use IlluminateHttpRequest;
use IlluminateSupportFacadesMail;
use AppHttpControllersController;

class SendEmailController extends Controller
{
    /**
     * Ship the given order.
     *
     * @param  Request  $request
     * @param  int  $orderId
     * @return Response
     */
    public function ship(Request $request)
    {
        $valueArray = [
        	'name' => 'John',
        ];

        // Test mail...
        
        try {
            Mail::to('[email protected]')->send(new TestMail($valueArray));
            echo 'Mail send successfully';
        } catch (Exception $e) {
            echo 'Error - '.$e;
        }
    }
}

Step : 4 Create email markdown controller

Here, we are create new one email markdown controller ans as well as email templete blade using following command


php artisan make:mail TestMail --markdown=emails.testmail

After run above command you can see TestMail.php file automatice created in app/Mail folder and your email templet/blade file testmail.php is created in resources/views/emails folders

Step : 5 Open your TestMail.php file

Now, open your app/Mail/TestMail.php file and make changes look like.


<?php
namespace AppMail;

use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;

class TestMail extends Mailable
{
	use Queueable, SerializesModels;
	/**
	 * Create a new message instance.
	 *
	 * @return void
	 */
	public function __construct($content)
	{
		$this->content = $content;
	}

	/**
	 * Build the message.
	 *
	 * @return $this
	 */
	public function build()
	{
		return $this->markdown('emails.testmail') //pass here your email blade file
	    	->with('content',$this->content);
	}
}

Step : 6 Open your testmail.blade.php file

[ADDCODE]

Now oprn your resources/views/emails/testmail.blade.php file and make changes look like.


@component('mail::message')
# Dear, {{$content['name']}}

You are receiving this email because we received a signup request for your this mail account.

@component('mail::button', ['url' => 'website.com')])
Click Here
@endcomponent

If you did not request a signup , no further action is required.

Thanks,
{{ config('app.name') }}
@endcomponent

Now we are ready to run our example so run bellow command ro quick run:

php artisan serve

Now you can open bellow URL on your browser:

http://localhost:8000/sendemail

I hope it can help you…

Hope this code and post will helped you for implement How to send email in laravel using markdown. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US