1

我正在使用SparkPost PHP API向收件人发送电子邮件,但我遇到了这个错误。目前我已经设置了所有必要的字段,但我仍然遇到大型电子邮件的问题。我可以轻松发送小文本,但我在处理大数据时遇到了困难。

[{"message":"缺少必填字段","description":"'content'中至少需要存在'text'或'html'之一","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();
    }
}
4

1 回答 1

1

发生这种情况是因为$resultarr['mailBody']未定义。

你确定数组$resultarr存在吗?如果是这样,则该mailBody元素必须丢失。

您可以提供text一部分或html一部分,或两者都提供。但是,如果您两者都不提供,您将收到错误:At least one of 'text' or 'html' needs to exist in 'content'.

在这种情况下,两者都没有提供,因为$resultarr['mailBody']未定义会导致数组的textandhtml元素未定义。

于 2016-01-14T19:30:42.387 回答