Cakphp 3 send mail with debug

In Laravel 5.3, you can send an email using the Mail facade and enable debug mode to see the email being sent. Here's an example:

Step 1: Create a mailer

In your app/Providers/EventServiceProvider.php file, add the following code:

public function boot()
{
    $this->app->bind('Illuminate\Support\Facades\Mail', function ($app) {
        return new \Illuminate\Mail\MailServiceProvider($app);
    });
}

Step 2: Create a mailer class

Create a new file app/Mail/Mailer.php with the following code:

namespace App\Mail;

use Illuminate\Mail\Mailer as LaravelMailer;

class Mailer extends LaravelMailer
{
    public function send($message, $callback = null)
    {
        return $this->sendRaw($message, $callback);
    }
}

Step 3: Send the email

In your controller or wherever you want to send the email, use the Mail facade to send the email:

use Illuminate\Support\Facades\Mail;

//...

Mail::to('[email protected]')->send(new MyEmail());

Step 4: Enable debug mode

In your config/mail.php file, set the debug option to true:

'debug' => true,

Step 5: Run the email sending

Run the following command in your terminal:

php artisan tinker

In the Tinker shell, run the following code:

use App\Mail\MyEmail;

Mail::to('[email protected]')->send(new MyEmail());

This will send the email and display the email being sent in the debug output.

Tips