mailjet / mailjet-apiv3-dotnet

[API v3] Official Mailjet API v3 .NET wrapper
https://dev.mailjet.com
MIT License
75 stars 31 forks source link

Mailjet V3 api correctly sending emails but not rendering variables #110

Closed GianmarcoVarroneDev closed 1 year ago

GianmarcoVarroneDev commented 1 year ago

Hello everybody,

I'm using the following code in my laravel app to send transactional email through mailjet. This code works correctly and the email is sent without any issue and received too. The issue is that the variables are not rendered into the template. Following is the code that Mailjet suggests me to use to send a specific template :
<?php /* This call sends a message to the given recipient with vars and custom vars. */ require 'vendor/autoload.php'; use MailjetResources; $mj = new MailjetClient(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3.1']); $body = [ 'Messages' => [ [ 'From' => [ 'Email' => "test@mail.com", 'Name' => "Closbox Help Center" ], 'To' => [ [ 'Email' => "passenger1@example.com", 'Name' => "passenger 1" ] ], 'TemplateID' => 4682979, 'TemplateLanguage' => true, 'Subject' => "{{var:subject:""}}", 'Variables' => json_decode('{ "subject": "", "title": "default", "body": "default", "thank": "defauklt", "signature": "default", "social-title": "default" }', true) ] ] ]; $response = $mj->post(Resources::$Email, ['body' => $body]); $response->success() && var_dump($response->getData()); ?>

While, this is the code that I'm using :

`$template_id =4682979;

                        $vars = [
                            "subject"=> trans("messages.help_ticket_subject",["number"=>"$ticket->number", "num"=>$booking->number], $booking->locale),
                            "social-title"=> trans("messages.general.social",[], $booking->locale),
                            "title" => trans("messages.help_ticket_title",["ticket_reference_number"=>$ticket->number], $booking->locale),
                            "body"=>trans("messages.help_ticket_body",["name"=>$booking->name, "ref_num"=>$ticket->number], $booking->locale),
                            "thank"=>trans("messages.general.thank_you",[], $booking->locale),
                            "signature"=>trans("messages.general.closbox_hc",[], $booking->locale)
                        ];
                        $mj = Mailjet::getClient();
                        $body = [
                            'Messages' => [
                                [
                                    "FromEmail"=>"test@mail.com",
                                    "To"=>"test@mail.com",
                                    'Mj-TemplateID' => 4682979,
                                    'TemplateLanguage' => true,
                                    'Subject' => trans("messages.help_ticket_subject",["number"=>"$ticket->number", "num"=>$booking->number], $booking->locale),
                                    'Variables'=>json_decode(json_encode($vars), true),
                                ]
                            ]
                        ];

                        $response = $mj->post(Resources::$Email, ['body' => $body]);`     

What could the reason be? The email is sent and the response received is 200. Thank you

dmytrosvystun88 commented 1 year ago

Hi @GianmarcoVarroneDev, please create an issue to PHP repository: https://github.com/mailjet/mailjet-apiv3-php/issues