msztolcman/sendria

Invalid type for field `to`

Opened this issue · 0 comments

Hello, I hope someone can point me to the right direction. I also referred to the following resources:

I have the following code snippet:

    $api_request_body = [];
    $api_request_body["from"] = ["name" => "test", "email" => $from];
    $api_request_body["to"] = ["name" => "somename", "email" => "some_email@gmail.com"];
    $api_request_body["subject"] = $subject;
    $api_request_body["text"] = $text;


    $ci = curl_init();
    
    curl_setopt($ci, CURLOPT_URL, "https://sandbox.api.mailtrap.io/api/send/1187930");
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ci, CURLOPT_ENCODING, "utf-8");
    curl_setopt($ci, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ci, CURLOPT_TIMEOUT, 0);
    curl_setopt($ci, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ci, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ci, CURLOPT_POSTFIELDS, json_encode($api_request_body));
    curl_setopt($ci, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$api_key, 'Content-Type: application/json'));

I am currently getting the error: 'invalid type for field to, expected: array, given: object'. I have attempted to changing the value to a single string, a single string declared within an array and the result varies slightly (as in: 'invalid type for field to, expected: array, given: string').