The Laravel 5.3 Mailer class is configured as a singleton according to this article https://laravel-news.com/allowing-users-to-send-email-with-their-own-smtp-settings-in-laravel
Let's assume a user in a requests sets Mail::setSwiftMailer to a different server in order to send mails via his mailserver/account.
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
$transport->setUsername('your_gmail_username');
$transport->setPassword('your_gmail_password');
$gmail = new Swift_Mailer($transport);
// Set the mailer as gmail
Mail::setSwiftMailer($gmail);
Does this affect other users? As far as I understood, the usual singleton characteristics do not apply in PHP http://blog.gordon-oheim.biz/2011-01-17-Why-Singletons-have-no-use-in-PHP/
A Singleton created in one Request lives for exactly that request. A Singleton created in another Request done at the same time will still be a completely different instance. And it will occupy it’s own memory. Those instances are not linked to each other. They are completely isolated, because PHP is a Shared-Nothing architecture. You do not have one single unique instance, but many similar instances in parallel processes.
So does changing the mailserver for the singleton function change the mailserver for other users?
Does changing the Laravel config affect the other users? I assume at least here the answer is yes.
Config::set('mail', ['driver' => $mail->driver, 'host' => $mail->host, 'port' => $mail->port, ...]);