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

matt_panton's avatar

php mail() laravel alternative?

I'm looking to rebuild one of my exisiting application using Laravel, basically it allows user to send templated emails to their clients such as 'Your booking has been confirmed' or 'Thank you for using us' etc... I currently us php's mail() function but I can't seem to find the alternative within Laravel. I want to use the Mail Facade so I can easily access templates as views. I've tried using gmail to send them but the messages end up in my junk.

Any advice is greatly appreciated :)

0 likes
10 replies
ChristopherSFSD's avatar

Mail::send() supports templates and everything you would need from the native PHP mail() function.

I'm not sure if I'm understanding your question entirely. You said you were looking for the alternative to mail() and then said you want to use Laravel's facade which implies that you are aware of the Laravel alternative -- the Mail facade.

Messages that end up in your junk mail may be for a whole host of reasons. Perhaps your junk filters are overly strong, perhaps Gmail thinks that the host you are sending from isn't reliable source, etc.

matt_panton's avatar

Thanks for your reply. What I want to do is use Mail::send() but not have it linked to any email account like how the php mail function doesn't need any authorisation, it just sends.... Hope this makes more sense

ChristopherSFSD's avatar
Level 4

In config/mail.php you probably need to change the driver to either "mail" or "sendmail"

I would argue that it's probably better to send out through a gmail account though because the message will appear to be coming from a more reliable source -- meaning your message is less likely to end up in the recipient's junkmail box. Plus you can log into the Gmail account to see bouncebacks and such.

matt_panton's avatar

Thanks, I've changed the driver to 'mail' now and it works. The problem I had with gmail was that the 'from' email address would be my actual gmail address and not the one that I defined when sending the message.

\Mail::send('emails.test', ['name'=>'Matt'], function($message){
        $message->to('me@hotmail.co.uk', 'Matt Panton')->from('test@example.com', 'Laravel test')->subject('email test');
    });
ChristopherSFSD's avatar

Yep gmail will override the from stuff. So maybe you want a dedicated Gmail account for the project.

matt_panton's avatar

The thing is, each user has their own email address for their messages to be sent from.

ChristopherSFSD's avatar

I see. Then gmail probably isn't the right answer. However if you are finding that a lot of the email is ending up in the junk box, you might want to consider some other mail delivery service.

matt_panton's avatar

What other delivery services are available? (sorry about all the questions)

ChristopherSFSD's avatar

There are plenty of SMTP services out there. The mail.php config file points to mailgun as an example. You'd need to create an account with the service provider you choose and then set your credentials (just like you did for Gmail). You'd also need to return the driver to SMTP.

matt_panton's avatar

Okay cool I'll give that a shot. Thanks so much for your help, I really do appreciate it. :)

Please or to participate in this conversation.