Reputation: 193
I am using SparkPost PHP API to send e-mail to recipient but I am facing this error. Currently I have set up all the necessary field but I still have problems with large e-mails. I can easily send small text but I'm having difficulties with large data.
[{"message":"required field is missing","description":"At least one of 'text' or 'html' needs to exist in 'content'","code":"1400"}]
My code is:
for ($j = 0; $j < count($result1arr); $j++) {
try {
SparkPost::setConfig(["key" => "XXXXX"]);
$results = Transmission::send(array(
"from" => "[email protected]",
"html" => $resultarr['mailBody'],
"text" => $resultarr['mailBody'],
"subject" => $resultarr['subject'],
"recipientList" => $result1arr[$j]['groupName']
));
$_SESSION['success_message'] = 'Email sended successfully to Recipient List with ID : ' . $data['recipients_id'];
$qry = "DELETE from mailQueue where mailQueueId={$result1arr[$j]['mailQueueId']}";
$res = $conn->query($qry);
$sql1 = "INSERT INTO sendMailHistory (schoolName,noOfMailSent) VALUES ('{$result1arr[$j]['originalGroupId']}','{$results['results']['total_accepted_recipients']}')";
$result1 = $conn->query($sql1);
$chc = curl_init();
curl_setopt($chc, CURLOPT_URL, "https://api.sparkpost.com/api/v1/recipient-lists/{$result1arr[$j]['groupName']}");
curl_setopt($chc, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($chc, CURLOPT_HEADER, FALSE);
curl_setopt($chc, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($chc, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($chc, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Authorization: XXXXX"
));
$response = curl_exec($chc);
curl_close($chc);
header('Location: ../index.php');
exit;
return true;
} catch (\Exception $exception) {
echo $exception->getMessage();
}
}
Upvotes: 1
Views: 4332
Reputation: 97
This is happening because $resultarr['mailBody']
is not defined.
Are you sure the array $resultarr
exists? If so, the mailBody
element must be missing.
You may supply either a text
portion or an html
portion, or both. But if you supply neither you will get the error: At least one of 'text' or 'html' needs to exist in 'content'
.
In this case neither are being supplied because $resultarr['mailBody']
being undefined causes the text
and html
elements of the array to be undefined.
Upvotes: 1