I am trying to integrate Mailjet API to send Bulk mails, where I read the documentation and wrote the necessary code to send the request, but I get the error as "ErrorCode" => "mj-0003". The mandatory parameters are From , To , TextPart. Even though I added all these parameters and they are not null either, I get the error as Mandatory parameters missing.
Below is my request code:
// Prepare Mailjet API request data
$client = Http::withHeaders([
'Content-Type' => 'application/json',
])->withBasicAuth('d550ed4*************42a9f48ae6', '3a4d*************b2fb');
$data = [
'Messages' => [
[
'From' => [
'Email' => 'test@gmail.com',
'Name' => 'Test',
],
'To' => [
'Email' => 'recievetest@gmail.com',
],
'Subject' => $subject,
'TextPart' => $content,
'HTMLPart' => "<h3>Dear passenger 1, welcome to </h3>",
'SandboxMode' => true,
],
],
];
// Send email using Mailjet API
$response = $client->post('https://api.mailjet.com/v3.1/send', [
'json' => $data,
]);
// Process the API response
$statusCode = $response->status();
$responseData = $response->json();
if ($statusCode == 200 && $responseData['Messages'][0]['Status'] == 'success') {
// Success
// return redirect()->back()->with('success', 'Emails sent successfully.');
dd($responseData);
} else {
// Error
// return redirect()->back()->with('error', 'Failed to send emails.');
dd($responseData);
}
And Below is the $data
array:1 [▼ // app/Http/Controllers/AdminController/ManageBulkEmailController.php:128
"Messages" => array:1 [▼
0 => array:6 [▼
"From" => array:2 [▼
"Email" => "test@gmail.com"
"Name" => "Test"
]
"To" => array:1 [▼
"Email" => "tets@gmail.com"
]
"Subject" => "Test"
"TextPart" => "Test Content"
"HTMLPart" => "<h3>test </h3>"
"SandboxMode" => true
]
]
]
And below is the response data $responseData
array:5 [▼ // app/Http/Controllers/AdminController/ManageBulkEmailController.php:128
"ErrorIdentifier" => "79519bb2-ee10-4759-aaf2-63f5718652da"
"ErrorCode" => "mj-0003"
"StatusCode" => 400
"ErrorMessage" => "Missing mandatory property."
"ErrorRelatedTo" => array:1 [▼
0 => "Messages"
]
]
I am creating this on Laravel framework. Don't know what I am missing. Here is the link for the documentation.