Why not just use one of these and then set the driver to mailjet
https://packagist.org/packages/mailjet/laravel-mailjet
https://packagist.org/packages/thedoctor0/laravel-mailjet-driver
Then you dont have to manually post to mailjet :)
Hi. I wanted to send mails with mailjet and mailjet templates. Mailjet offers a way to design templates in the service, that no developer is needed for changes. So I dont need the views and design to make in laravel. I only send an ID to Mailjet, which template to use and send also variables if needed. My question is, is it still ok to use mailables? I did a check and it work. And maybe you say, yes this is the right way, but I wanted to know that it is not wrong or you say "dont do it, because of...". This is what I have and works:
class TestMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
public function send($mailer)
{
$mj = Mailjet::getClient();
$body = [
'FromEmail' => "[email protected]",
'FromName' => "John",
'Subject' => "My Testmail",
'MJ-TemplateID' => 1234567,
'Recipients' => [['Email' => "[email protected]"]]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
}
}
For me it makes sense to use Mailables, because I have an overview and when I change someday I can change all at once instead of searching my mail code in the whole code. Is it ok to overwrite the send method?
For all with the same idea: It works. You can create a Mailable and override the send method. I wrote a trait i use in my mailable, which offers the function to send via API the mail. The good thing is that ShouldQueue works. First I thougt it dont, but I had first to setup Jobs in laravel and then switch from sync to database in .env. This is only a tip for people who also think it will not work. Now I can use the templates at mailjet (others services will also work I think) and can seperate the developer work from marketing work. Hope that helps.
Please or to participate in this conversation.