Sending E-Mail with Laravel 4 using mail

In this short post I will show you how you can send emails with Laravel 4 using the built in mail function of PHP. I don’t want to use any other email transport at this point and just plain PHP mail function can be utilized for sending emails.

It is super easy to send mail with new Laravel 4 functionality without installing any other packages. Laravel 4 has Mail function that uses SwiftMailer as a dependency (but I want to stress it again, you do not need to install anything, Laravel 4 already comes with it).

First and foremost, go to the app/config/mail.php and change the driver to “mail”. Also put the host as blank.

Here is a quick example, in the controller or in the model where I want to send the mail :

// I'm creating an array with user's info but most likely you can use $user->email or pass $user object to closure later
$user = array(

// the data that will be passed into the mail view blade template
$data = array(
	'detail'=>'Your awesome detail here',
	'name'	=> $user['name'];

// use Mail::send function to send email passing the data and using the $user variable in the closure
Mail::send('emails.welcome', $data, function($message) use ($user)
  $message->from('', 'Site Admin');
  $message->to($user['email'], $user['name'])->subject('Welcome to My Laravel app!');

This example above will use the Blade template under views/emails/welcome.blade.php , the contents of that template below:

<!DOCTYPE html>
<html lang="en-US">
		<meta charset="utf-8">
		<h2>Welcome to my site</h2>

			Your sign up details are below:
		<div>{{ $detail }}</div>
		<div>{{ $name}} </div>

Let me know if you have any questions!

As suggested by Twitter user Ryan Tablada, you can find tons of great email templates at this link :

In the current version of Laravel (4.0.6) you can set “pretend” setting in mail.php to true and instead of actually sending the emails you will instead see them in the application logs. This is super helpful when trying to test and debug email capabilities.

You may also like

  • Hi,

    Thanks for your tutorial.
    I used the tutorial and set a filter which showed the execution was a success but the problem is it did not send the mail to the set address email address.

    How can I achieve this without using SwiftMailer because your solution is the only one which has got me where I am at the moment.

    Greatly appreciate your help.

  • Thanks for this tutorial! How would I go about sending the message to more than one person?

  • Maks Surguy

    have you tried separating the emails with a comma, ex :
    $message->to(’,,‘)->subject(‘Welcome to My Laravel app!’);

  • Renato Theodoro

    Great! This article helped me!

  • Maks Surguy

    Were you able to solve this problem?

  • Great post!
    For Jesse
    You just need to pass an array containing all the email;
    $to = array(’email1@domain.tld’, ’email2@domain.tld’);

    and then…

    Mail::send(’emails.welcome’, $data, function($message) use ($to)
    $message->from(‘’, ‘Site Admin’);
    $message->to($to)->subject(‘Welcome to My Laravel app!’);

  • Pingback: Missing notes for Laravel 4 | Andrews Blog()

  • Tortue Torche

    Great Mail class introduction.
    By the way, there is a typo in:

    $data = array(
        ‘detail’=>’Your awesome detail here’,
        ‘name’  => $user[‘name’];

    Should be :

    $data = array(
        ‘detail’=>’Your awesome detail here’,
        ‘name’  => $user[‘name’],

  • Max


    what’d be the best way to check the mailserver response?
    e.g. I am using SMTP; I have tried along the lines of

    $returncode = Mail::send(…….)

    Log::info( ….. $returncode)

    but to no avail at all. It’s a bit a shot in the dark not to be able to check whether the emails made it to the smtp server so as to know whether to delete / requeue the job…

  • Justin

    How do I verify if email was sent successfully ?

    Does Mail::send() it throws true or false?

  • Maks Surguy

    I believe it is the same as using Swiftmailer (that powers Laravel’s mail functionality) so yes, I believe it does return true or false depending on status.

  • Great tuts

  • Hi. Short and useful post. But I get email with empty body. Anything missing from my part?

  • Make sure you have the view template that has content in it. For example views/emails/welcome.blade.php should have content.

  • VitaliiSestrinskiy


  • Shashi Kumar

    This one is the good help for starting.

    Please same give one atachment xls file in the same mail ,pls suggest me
    Thank you
    shashi kumar

  • Classical


    use ($user) help me to transfer variable 🙂

  • jasmin jasmin

    I already did like your tutorial. There is no error but the mail is not sent.
    What is the problem?

  • karthick

    Anyone help me I tried lot of methods to send mail but i am getting error class ‘mail’ not found

  • maxsurguy

    That means your PHP does not have ‘mail’ extension! You need to recompile your PHP installation with mail extension.

  • karthick

    Thanks for ur reply ok i will do.

  • al

    public function fire() {
    echo ‘~1′;
    Mail::send(’emailstest’, array(), function($message){
    echo ‘~2’;
    $message->to(‘’, ‘testing’)->subject(‘hello’);
    echo ‘~3’;
    echo ‘~4’;

    Does any one help?

    4 echo messages came out perfectly, but no messages being sent.

More in Code Blog
Laravel 4 release

Hey Laravel users! Laravel version 4 has been released this Tuesday! I feel you cheering and smiling because this means...