I'm trying to change SMTP details on the fly for web or queue also.
I have tried this link : https://laravel-news.com/allowing-users-to-send-email-with-their-own-smtp-settings-in-laravel, but this example not working in Laravel 10.
Not only that, but I also try this code :
$configuration = $this->configuration();
$customer = Customer::find(1);
$notification['message'] = "Message";
$mailer = new CustomerMail($customer, $notification['message'], $configuration['smtp_from_email'], $configuration['smtp_from_name']);
$mailer->withSwiftMessage(function ($message) use ($configuration) {
$message->getHeaders()
->addTextHeader('X-SMTP-Transport', $configuration['smtp_transpot'])
->addTextHeader('X-SMTP-Host', $configuration['smtp_host'])
->addTextHeader('X-SMTP-Port', $configuration['smtp_port'])
->addTextHeader('X-SMTP-Encryption', $configuration['smtp_encryption'])
->addTextHeader('X-SMTP-Username', $configuration['smtp_username'])
->addTextHeader('X-SMTP-Password', $configuration['smtp_password']);
});
Mail::to($customer->{Customer::EMAIL})->send($mailer);
This code also not working for me, How can I change SMTP details on the fly in Laravel 10 without effecting config values.
Laravel10 using Symfony Mailer instead of SwiftMailer. https://laravel.com/docs/9.x/upgrade#symfony-mailer
config overrides are temporary and are not saved.
This only takes effect during the current request.