Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel多邮件配置和多个并发用户_Php_Laravel_Concurrency_Swiftmailer - Fatal编程技术网

Php Laravel多邮件配置和多个并发用户

Php Laravel多邮件配置和多个并发用户,php,laravel,concurrency,swiftmailer,Php,Laravel,Concurrency,Swiftmailer,我正在使用Laravel5.3,我有一个关于多个邮件的问题。我的默认邮件程序在配置中设置。根据其他帖子中的建议,当我想从另一台服务器发送邮件时,我将使用此脚本更改默认邮件程序 // Backup your default mailer $backup = Mail::getSwiftMailer(); // Setup your gmail mailer $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, '

我正在使用Laravel5.3,我有一个关于多个邮件的问题。我的默认邮件程序在配置中设置。根据其他帖子中的建议,当我想从另一台服务器发送邮件时,我将使用此脚本更改默认邮件程序

// 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);
所以我的问题是澄清。假设有多个用户同时发送邮件。如果它们都设置了Mail::setSwiftMailer,那么这只会影响我的应用程序的各个实例,而不会影响整个应用程序,对吗?我想避免一个用户从一个为另一个用户准备的帐户发送邮件

更新:

我怀疑,只要我不按如下所示更改配置值,Mail::SetswitMailer就只为当前用户设置邮件程序。对吗

$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);

Mailer类被配置为单例。据我所知,这并不意味着通常的单例特征适用

在一个请求中创建的单例正好适用于该请求。A. 在同一时间完成的另一个请求中创建的Singleton仍将 这是一个完全不同的例子。它会占据自己的地盘 记忆力这些实例之间没有链接。他们是 完全隔离,因为PHP是一个不共享的体系结构。你 没有一个唯一的实例,但在中有许多类似的实例 并行进程

所以设置Mail::setswitmailer$gmail;应该没问题。无论如何,我找到了一个使用新邮件的解决方案

下面的链接描述了该问题,并显示了laravel 5.8的解决方案

对于Laravel5.3,您需要像这样创建邮件程序,因为助手函数app->get'view'不存在

$mailer=new-Mailerapp'view',$swift_-mailer,app'events'