SparkPost 发送电子邮件模板
SparkPost sending e-mail Template
我正在使用 SparkPost PHP API 向收件人发送电子邮件,但我遇到了这个错误。目前我已经设置了所有必要的字段,但我仍然遇到大型电子邮件的问题。我可以轻松发送小文本,但我在处理大数据时遇到困难。
[{"message":"required field is missing","description":"At least one of 'text' or 'html' needs to exist in 'content'","code":"1400"}]
我的代码是:
for ($j = 0; $j < count($result1arr); $j++) {
try {
SparkPost::setConfig(["key" => "XXXXX"]);
$results = Transmission::send(array(
"from" => "test@universityfood.co",
"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();
}
}
发生这种情况是因为 $resultarr['mailBody']
未定义。
你确定数组 $resultarr
存在吗?如果是这样,则必须缺少 mailBody
元素。
您可以提供 text
部分或 html
部分,或同时提供两者。但是,如果您都不提供,则会出现错误:At least one of 'text' or 'html' needs to exist in 'content'
.
在这种情况下,两者都没有被提供,因为 $resultarr['mailBody']
未定义导致数组的 text
和 html
元素未定义。
我正在使用 SparkPost PHP API 向收件人发送电子邮件,但我遇到了这个错误。目前我已经设置了所有必要的字段,但我仍然遇到大型电子邮件的问题。我可以轻松发送小文本,但我在处理大数据时遇到困难。
[{"message":"required field is missing","description":"At least one of 'text' or 'html' needs to exist in 'content'","code":"1400"}]
我的代码是:
for ($j = 0; $j < count($result1arr); $j++) {
try {
SparkPost::setConfig(["key" => "XXXXX"]);
$results = Transmission::send(array(
"from" => "test@universityfood.co",
"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();
}
}
发生这种情况是因为 $resultarr['mailBody']
未定义。
你确定数组 $resultarr
存在吗?如果是这样,则必须缺少 mailBody
元素。
您可以提供 text
部分或 html
部分,或同时提供两者。但是,如果您都不提供,则会出现错误:At least one of 'text' or 'html' needs to exist in 'content'
.
在这种情况下,两者都没有被提供,因为 $resultarr['mailBody']
未定义导致数组的 text
和 html
元素未定义。