Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel global send to address for testing

I know how to set a global 'from' address in Laravel's mailer but I need to set a global 'to' address.

I want to see the output of the emails but not send them to the actual user just yet.

Swiftmailer has a delivery_address setting which does this but I can't seem to find this in Laravel's config.

like image 989
Mark Tierney Avatar asked Sep 17 '25 00:09

Mark Tierney


2 Answers

I know this is an old question but maybe it's still relevant to someone.

Instead of returning the config array in config/mail.php you could define the global TO address depending on the App Environment:

$config = [
// ... default laravel configuration ...
];

// global TO Address for all sent mails
if (env('MAIL_TO_ADDRESS') && env('APP_ENV') !== 'production') {
    $config['to'] = [
        'address' => env('MAIL_TO_ADDRESS'),
        'name' => env('MAIL_TO_NAME', 'Example'),
    ];
}

return $config;

Now you can define [email protected] in your .env file, which will only take effect when the environment is not in production.

like image 173
pnzz7 Avatar answered Sep 18 '25 14:09

pnzz7


Check this in Laravel documentation: Using a global to address in Laravel. It exists since version 8.

like image 37
Amr Avatar answered Sep 18 '25 14:09

Amr