How to Send Mail in PHP Laravel?

How to Send Mail in PHP Laravel?

In this post we will give you information about How to Send Mail in PHP Laravel?. Hear we will give you detail about How to Send Mail in PHP Laravel?And how to use it also give you demo for it if it is necessary.

Laravel 5 provide several way to send email. You can also use core PHP method for send mail and you can also use some email service providers such as sendmail, smtp, mandrill, mailgun, mail, gmail etc. So you can choese any one and set configration. Laravel 5 provide Mail facade for mail send that have sevaral method for send email.In this example i going to show you how to send emails from gmail account example. This example is very simple you can use as requirement easily. It is very simple to configration with gmail account so first open your .env file and add bellow gmail configration.

.env

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=harshadpathak1313@gmail.com

MAIL_PASSWORD=mypassword

MAIL_ENCRYPTION=tls

Now we are ready to send mail for test so first create test route for email sending.

app/Http/routes.php

Route::get('mail', 'HomeController@mail');

Ok, now add mail function in HomeController.php file so add this way :


app/Http/Controllers/HomeController.php

public function mail()

{

$user = User::find(1)->toArray();


Mail::send('emails.mailExample', $user, function($message) use ($user) {

$message->to($user->email);

$message->subject('E-Mail Example');

});


dd('Mail Send Successfully');

}

At last create email template file for send mail so let’s create mailExample.blade.php file in emials folder.

resources/views/emails/mailExample.blade.php

Also see:Laravel Mailchimp api integration from scratch with example

Hello {{ $name }}, I am from Itsolutionstuff.com.

If you still found any error then follow this link : How to set gmail configration for mail in Laravel?.

Video

Hope this code and post will helped you for implement How to Send Mail in PHP Laravel?. 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

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  11  =  13

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