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.
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.
Check this in Laravel documentation: Using a global to
address in Laravel. It exists since version 8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With