Framework: Laravel mail queue Missing argument 1 for Illuminate\Support\Manager::createDriver()

Created on 26 Jul 2016  路  6Comments  路  Source: laravel/framework

I have create a setting table in database for email settings. When email send function called I set my mail configuration on fly. It is working in Mail::send() but not in Mail::queue.

public function setMailConfig($from_address) {
    $username = $from_address->email_address;
    $fromname = $from_address->email_name;
    $password = \Crypt::decrypt($from_address->password);
    $smtpsecure = $from_address->sending_encryption;
    $host = $from_address->sending_host;
    $port = $from_address->sending_port;
    $protocol = $from_address->sending_protocol;
    $configs = [
        'username' => $username,
        'from' => ['address' => $username, 'name' => $fromname,],
        'password' => $password,
        'encryption' => $smtpsecure,
        'host' => $host,
        'port' => $port,
        'driver' => $protocol,
    ];
    foreach ($configs as $key => $config) {
        if (is_array($config)) {
            foreach ($config as $from) {
                \Config::set('mail.' . $key, $config);
            }
        } else {
            \Config::set('mail.' . $key, $config);
        }
    }
}

By default my queue driver is database. In job table it has populated. I called the command php artisan queue:listen --tries=1 . After 1 attempt queue saved to failed_job table.

public function laravelMail($to, $toname, $subject, $data, $cc, $attach) {
    try {
        $mail = Mail::queue('emails.mail', ['data' => $data], function ($m) use ($to, $subject, $toname, $cc, $attach) {

                    $m->to($to, $toname)->subject($subject);

                    if ($cc != null) {
                        foreach ($cc as $collaborator) {
                            //mail to collaborators
                            $collab_user_id = $collaborator->user_id;
                            $user_id_collab = User::where('id', '=', $collab_user_id)->first();
                            $collab_email = $user_id_collab->email;
                            $m->cc($collab_email);
                        }
                    }

                    //            $mail->addBCC($bc);

                    if ($attach != null) {
                        $size = count($attach);
                        for ($i = 0; $i < $size; $i++) {
                            $file_name = $attach[$i]->getClientOriginalName();
                            $file_path = $attach[$i]->getRealPath();
                            $mime = $attach[$i]->getClientMimeType();
                            $m->attach($file_path, ['as' => $file_name, 'mime' => $mime]);
                        }
                    }
                });
        return $mail;
    } catch (\Exception $e) {
        \Log::info($e->getMessage());
    }
}

I changed my .env file to MAIL_DRIVER= MAIL_HOST= MAIL_PORT= MAIL_USERNAME= MAIL_PASSWORD= CACHE_DRIVER= SESSION_DRIVER= QUEUE_DRIVER= But still Mail::queue is not working. Please suggest some idea.

Most helpful comment

Thanks.

All 6 comments

What laravel version please?

laravel 5.2

Please provide the full version. :)

Laravel Framework version 5.2.39

Thanks.

Thanks, but I don't think this is an issue in the framework on invesitgation. Please feel free to ask around on the forums. We typically don't recommend setting config at runtime like that. If you need to construct a custom mailer, I'd recommend actually newing up this class manually.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  路  3Comments

felixsanz picture felixsanz  路  3Comments

JamborJan picture JamborJan  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments