Did you cache your config with log as the MAIL_MAILER?
php artisan config:clear
Or, modify the config/mail.php configuration file to hardcode log as the default mailer?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm a beginner using Laravel, I'm trying to send notification with Notification facade. I have tried it using both Notification facade as well as Notifiable trait. The problem is the mail I'm sending is being logged into storage\logs\laravel.log file and not sending to my mailtrap inbox. I have configured the .env file with the credentials provided by mailtrap.io. I don't know what I'm doing wrong here.
web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
// chaining middleware to the route
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])
->name('home');
->middleware('auth');
Route::get('payment/create', [App\Http\Controllers\PaymentController::class, 'create'])->middleware('auth');
Route::post('payment', [App\Http\Controllers\PaymentController::class, 'store'])->middleware('auth');
.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=<mailtrap username>
MAIL_PASSWORD=<mailtrap password>
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME=Example
config\mail.php
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
]
PaymentController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Notifications\PaymentRecieved;
use Illuminate\Support\Facades\Notification;
use App\Models\User;
class PaymentController extends Controller
{
public function create()
{
return view('payment');
}
public function store()
{
Notification::send(request()->user(), new PaymentRecieved());
// request()->user()->notify(new PaymentRecieved());
return redirect('payment/create')->with('msg','Notified');
}
}
PaymentRecieved.php
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class PaymentRecieved extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
User.php
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Any help would be appreciable. Thank You.
Did you cache your config with log as the MAIL_MAILER?
php artisan config:clear
Or, modify the config/mail.php configuration file to hardcode log as the default mailer?
Please or to participate in this conversation.