【问题标题】:Mailgun batch email sending doesn't work when no. of recipient is more then 2000Mailgun 批量发送电子邮件在否时不起作用。收件人超过 2000
【发布时间】:2016-01-25 07:38:30
【问题描述】:

我用来通过Mailgun Api发送批量邮件的这个功能,它在没有时工作。收件人的数量小于 1000,但收件人大于 2000 时失败。

我正在做的是,我正在获取收件人列表,然后将它们分成 5 组(1 批邮件中的 5 位收件人)。批量邮件包含各种内容占位符(%recipient.name%),在从 Mailgun 发送批量邮件时,这些占位符会被原始数据替换,此外,我还在批量邮件中添加一些自定义数据以跟踪 Mailgun 日志中的邮件

.

/**
 * Used to send batch mails
 * @param text $subject content mail subject
 * @param text $text content mail in text body
 * @param array $from sender details
 * @param array $recipients content all recipients details
 * @param text $htmlBody content mail html content
 * @param int $type content mail type
 * @param int $broadcastId batch mail id
 * @param int $broadcastType type of broadcast email
 * @param int $isUser content user or contact
 * @return boolean
*/
public function sendBatchMail($subject, $text, $from = '',          $recipients = array(), $htmlBody = '', $type = '', $broadcastId = '',
        $broadcastType = '', $isUser = '')
{

    //get the broadcast mailgun info
    $this->_mgClient = apiKey;
    $this->_domain = domain;

    // divide batch mail in chunk of 5(sending 5 emails in 1 batch mail)
    $recipientsArr = array_chunk($recipients, 5);

    try {
        foreach ($recipientsArr as $allRecipient) {
            $batchMsg = $this->_mgClient->BatchMessage($this->_domain);

            // Define the subject.
            $batchMsg->setSubject($subject);

            // Define the body of the message.
            $batchMsg->setTextBody($text);

            $batchMsg->setHtmlBody($htmlBody);

            // filter from and set
            $from = $this->_getBatchDetail($from);

                $batchMsg->setFromAddress(
                    $from['email'], $from['detail']
                );

            // loop through $allRecipient and add recipient
            if (is_array($allRecipient)) {
                $customData = array();
                foreach ($allRecipient as $eachRecipient) {
                    // filter recipient and set
                    $to = $this->_getBatchDetail($eachRecipient);
                    if ($to) {
                        $data['accountId']
                            = !empty($eachRecipient['accountId'])
                            ? $eachRecipient['accountId'] : '';
                        $data['recipientId']
                            = !empty($eachRecipient['id'])
                            ? $eachRecipient['id'] : '';
                        $data['subject'] = $subject;
                        $data['sendDate'] = date("Y-m-d H:i:s");
                        $data['mailType'] = $type;
                        $data['mailId'] = $broadcastId;
                        $data['broadcastType'] = $broadcastType;
                        $data['recipientType'] = $isUser;
                        $data['email'] = !empty($eachRecipient['email'])
                            ? $eachRecipient['email']
                            : '';
                        $customData[] = $data;
                        $batchMsg->addToRecipient(
                            $to['email'],
                            $to['detail']
                        );
                    }
                }
                $batchMsg->addCustomData('custom-data', $customData);
            }

            // Call finalize() to send any remaining recipients still in the buffer.
            $batchMsg->finalize();
        }
        // finalize doesn't return anything. so if dont through any error, its a success
        return true;
    } catch (Exception $ex) {
        error_log($ex->getMessage());
        return false;
    }

}

【问题讨论】:

    标签: mailgun


    【解决方案1】:

    根据他们的文档 (https://documentation.mailgun.com/user_manual.html#batch-sending),允许批量发送的最大收件人数量为 1000,因此请将您的批次控制在此范围内。

    【讨论】:

      猜你喜欢
      • 2015-09-15
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 2016-10-06
      相关资源
      最近更新 更多