Closed ediblemanager closed 3 years ago
After some time I figured out how to work with both Beautymail and the default Laraval Mailer + Queueing.
The Mailer Class you've created above is fine.
You should call it with the default method: Mail::to($reciever_mail)->queue(new Newuser($member));
This method will queue the mail and send it with your queue walker. In my case I've chosen the 'Sunny' template which returns errors about missing variables. I've solved it with adding the Beautymailer config variables to the view:
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('E-mail subject')
->view('emails.viewname', config('beautymail.view'));
}
I agree this one is a bit confusing and it took me some time to figure it out. Readme should be improved with documentation about queueing.
@wespiremedia Great debug for solving the queue issue. I will happily accept a PR with readme changes regarding this.
(I'm not using queues with Beautymail)
`Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Illuminate\Mail\Mailable::view() must be of the type array, null given, called in /var/www/app/Mail/SendMessage.php on line 32 in /var/www/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php:687 Stack trace:
According to the instructions above :(
`class SendMessage extends Mailable implements ShouldQueue { use Queueable, SerializesModels;
public $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function build()
{
return $this
->from(config('mail.from.address'))
->to($this->user->email)
->subject('DB Design')
->view('emails.welcome', config('beautymail.view'));
}
}`
Based on the error, config('beautymail.view')
returns 'null' instead of a config array.
Does the config/beautymail.php file exists? Otherwise you should include them from the repo.
Just an FYI for anyone else trying to figure this out. Just doing the below seems to have gotten everything to work for me, keeping Mailable.
class ReportMail extends Mailable
{
public function build()
{
// Do stuff...
$beautymail = app()->make(Beautymail::class);
return $this->view('emails.report', $beautymail->getData());
}
}
Note instead of passing in config('beautymail.view'), you should pass $beautymail->getData(). That way Beautymail is able to set the css and correct logo path.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I get the feeling I'm missing something: Beautymail is a drop-in replacement for Mail, isn't it? So queueing should work without any issues.
This is Laravel 5.5 running on Ubuntu 14.04, PHP 7.0.
When running
$beautymail->queue('emails.welcome', [], new NewUser($member));
, (NewUser
being a mailable, whichimplements ShouldQueue
), I get the errorInvalidArgumentException: Only mailables may be queued.
Swapping out Beautymail for Mail fixes the issue.
Mailer class:
Stack trace: