I have a swift mailer in Laravel 5.8 and it send an email with user smtp setting. It works well manually, but when I use this within queue, mailer setting is reverted to default setting. Code is like this.
if($own_stmp){
$transport = (new Swift_SmtpTransport($user->mail_host, $user->mail_port))
->setUsername($user->mail_username)
->setPassword($user->mail_password);
}else{
$transport = (new Swift_SmtpTransport(\Config::get('mail.host'), \Config::get('mail.port')))
->setUsername(\Config::get('mail.username'))
->setPassword(\Config::get('mail.password'));
}
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
if($own_stmp){
$message = (new Swift_Message($subject))
->setFrom([$user->mail_from_address => $agent->name])
->setTo([$lead->email => $lead->name])
->setReplyTo($agent->email)
->addPart($content, 'text/html');
} else {
$message = (new Swift_Message($subject))
->setFrom([\Config::get('mail.from.address') => $agent->name])
->setTo([$lead->email => $lead->name])
->setReplyTo($agent->email)
->addPart($content, 'text/html');
}
// Send the message
$result = $mailer->send($message);
As you can see, it changes email setting by $own_smtp flag.
This is really working well, but when I use this with
php artisan queue:work
It is skipped custom user setting and send with default setting.
What is wrong? How to solve this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire