Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AlsonicTech's avatar

Laravel Mail not working and php function mail() does

Hey guys,

I had this issue last month while testing another app on a DigitalOcean VPS then I changed the mail driver to Mailgun.

Right now I just moved a new project from testing server (where everything was working OK) to a production server. The issue is that on the production server Laravel Mail doesn't work and doesn't want to send email.

So I tested the PHP mail() function and it works perfect.

I tested the next configurations and did not work.

.env MAIL_DRIVER=mail

app/mail.php 'driver' => 'mail'

I don't receive any errors and when executing dd(Mail::failures()); I get an array with the email that wasn't sent.

Is this a server issue, that doesn't let Laravel to execute the mail function or is this a Laravel issue?

0 likes
14 replies
ejdelmonico's avatar

MAIL_DRIVER should be = "mailgun" and make sure MAIL_PRETEND=false. Also, set your appropriate MAIL_HOST

1 like
AlsonicTech's avatar

Sorry for the misunderstanding, but I said that I tested "ANOTHER" app and that time the solution was to move mail driver to MAILGUN. '

This app right now needs to have the mail driver MAIL. So everything is working perfect on the test server, but on the production server there is an issue.

AlsonicTech's avatar

So what exactly should be the issue and how it can be fixed so that the MAIL driver will work in the Laravel app ?

ejdelmonico's avatar

Post your relevant code for more help. It should work fine if the code is right.

AlsonicTech's avatar

So to clarify something, I did not changed anything from the localhost and test servers, so the projects is moved without any modification. The only thing I did modified was the database user and pass :)

I created a route to test the MAIL sending:

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

    $data = [
        'key'     => 'value'
    ];

    Mail::send('emails.test', $data, function ($message) {
        $message->from('another@email.com', 'My name');
        $message->subject('subject');
        $message->to('my@email.com');
    });

    dd(Mail::failures());
});

.env file contains MAIL_DRIVER=mail

config/mail.php file contains 'driver' => env('MAIL_DRIVER', 'mail')

And the php mail() function it works perfect.

1 like
ejdelmonico's avatar

Mail::send is using the Laravel mail facade I believe. Thus, it should use php mail() if driver set to that. What mail server are you using to actually send the mail? i.e MAIL_HOST=???

ybresson's avatar

I had a similar issue, Laravel was unable to send emails via 'mail' driver (MAIL_DRIVER=mail).

Removing the 'from' header (comment out // $message->from('[email protected]', 'name');) and setting all other mail related settings in my .env file to null solved the problem for me: MAIL_HOST=null MAIL_PORT=null MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null

aweishaar's avatar

I can confirm that @ybresson suggestion about setting all other mail related settings in my .env file to null worked for me without removing the from header.

bhavinsoni's avatar

Can i have mail using php mail() function without using any host like smtp?

laguiz's avatar

Config that works for me :

MAIL_DRIVER=mail
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME=null

I already have a default [email protected] configured on my server.

1 like
wesamly's avatar

Thank you guys,

Below worked for me:

MAIL_DRIVER=mail
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
[email protected]
MAIL_FROM_NAME=Example
1 like
napstervivek's avatar

@wesamly thanks bro, i really tired from this issue from last 3 to 4 days...this really works for me...thanks a lot again

Please or to participate in this conversation.