$email]; $postData = [ "to" => $to, "" /> $email]; $postData = [ "to" => $to, "" /> $email]; $postData = [ "to" => $to, ""/>

{"errors":["invalid type for field `to`, expected: `array`, given: `object`"]}

259 Views Asked by At

Trying to send an email from php using mailtrap api giving me the error above for the to field
`

$to = ["email"=>$email];
        $postData = [
            "to" => $to,
            "from"=> "[email protected]",
            "name"=>" Please Verify Email Address!",
            "subject" => " Verify Email and Complete Registration",
            "sender_id" => "ym",
            "callback_url" => "ym.com",
            "text" => $msg,
            "category"=> $type."Email Verification - Onboarding"
        ];
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://send.api.mailtrap.io/api/send',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POSTFIELDS => json_encode($postData),
            CURLOPT_HTTPHEADER => array(
                'Authorization: Bearer 99',
                'Content-Type: application/json'
            ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);
        echo $response;`

I am expecting to send the email succesfully

0

There are 0 best solutions below