I am using Laravel 5.3 and I have a question regarding multiple mailers. My default mailer is set in the config. Following suggestions in other posts, I would use this script to change the default mailer when I want to send a mail from another server.
// Backup your default mailer
$backup = Mail::getSwiftMailer();
// Setup your gmail mailer
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
$transport->setUsername('your_gmail_username');
$transport->setPassword('your_gmail_password');
// Any other mailer configuration stuff needed...
$gmail = new Swift_Mailer($transport);
// Set the mailer as gmail
Mail::setSwiftMailer($gmail);
// Send your message
Mail::send();
// Restore your original mailer
Mail::setSwiftMailer($backup);
So my question is one of clarification. Let's assume there are multiple users concurrently sending mails. If all of them are setting Mail::setSwiftMailer, this will only affect the respective instance of my application, not the whole application, right? I want to avoid that one user sends a mail from an account that is intended for another user.
UPDATE:
I would suspect that as long as I don't change the config values as below, Mail::setSwiftMailer only sets the Mailer for the current user. Is that correct?
$mail=DB::table('mail_settings')->first();
$config = array(
'driver' => $mail->driver,
'host' => $mail->host,
'port' => $mail->port,
'from' => array('address' => $mail->from_address, 'name' => $mail->from_name),
'encryption' => $mail->encryption,
'username' => $mail->username,
'password' => $mail->password,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false
);
Config::set('mail',$config);