Mandrill API 电子邮件使用模板排队

Mandrill API email getting Queued with use of Template

我正在尝试使用 mandrill api 发送带模板的电子邮件。我正在处理此处记录的方法:https://mandrillapp.com/api/docs/messages.php.html#method=send-template 代码在URL中实现:http://ezaccom.com/mxl.php 我的问题是我所有的电子邮件都在排队,而不是像他们应该的那样快速发送。这是代码(注意 %TEMPLATE CODE% 是我的电子邮件模板所在的位置):

 try {
$mandrill = new Mandrill('API_KEY_REDACTED');
$template_name = 'Welcome mail on email /FB sign-up to very email id';
$template_content = array(
    array(
        'name' => 'Welcome mail on email /FB sign-up to very email id',
        'content' => 'sign-up'
    )
);
$message = array(
    'html' => '%TEMPLATE CODE%',
    'text' => 'Example text content',
    'subject' => 'Welcome to Easyaccom',
    'from_email' => 'hello@easyaccom.com',
    'from_name' => 'Easyaccom',
    'to' => array(
        array(
            'email' => 'RECIPIENT@gmail.com',
            'name' => 'Jordan Belfort',
            'type' => 'to'
        )
    ),
    'headers' => array('Reply-To' => 'message.reply@example.com'),
    'important' => false,
    'track_opens' => null,
    'track_clicks' => null,
    'auto_text' => null,
    'auto_html' => null,
    'inline_css' => null,
    'url_strip_qs' => null,
    'preserve_recipients' => null,
    'view_content_link' => null,
    'bcc_address' => 'message.bcc_address@example.com',
    'tracking_domain' => null,
    'signing_domain' => null,
    'return_path_domain' => null,
    'merge' => true,
    'merge_language' => 'mailchimp',
    'global_merge_vars' => array(
        array(
            'name' => 'merge1',
            'content' => 'merge1 content'
        )
    ),
    'merge_vars' => array(
        array(
            'rcpt' => 'recipient.email@example.com',
            'vars' => array(
                array(
                    'name' => 'merge2',
                    'content' => 'merge2 content'
                )
            )
        )
    ),
    'tags' => array('password-resets'),
    'subaccount' => 'customer-123',
    'google_analytics_domains' => array('example.com'),
    'google_analytics_campaign' => 'message.from_email@example.com',
    'metadata' => array('website' => 'www.example.com'),
    'recipient_metadata' => array(
        array(
            'rcpt' => 'recipient.email@example.com',
            'values' => array('user_id' => 123456)
        )
    ),
    'attachments' => array(
        array(
            'type' => 'text/plain',
            'name' => 'myfile.txt',
            'content' => 'ZXhhbXBsZSBmaWxl'
        )
    ),
    'images' => array(
        array(
            'type' => 'image/png',
            'name' => 'IMAGECID',
            'content' => 'ZXhhbXBsZSBmaWxl'
        )
      )
    );
   $async = false;
$ip_pool = 'Main Pool';
$send_at = 'example send_at';
$result = $mandrill->messages->sendTemplate($template_name, $template_content, $message, $async, $ip_pool);
print_r($result);
/*
Array
(
    [0] => Array
        (
            [email] => recipient.email@example.com
            [status] => sent
            [reject_reason] => hard-bounce
            [_id] => abc123abc123abc123abc123abc123
        )

)
*/
} catch(Mandrill_Error $e) {
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
// A mandrill error occurred: Mandrill_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
throw $e;
  }
   ?>

您有很多未明确设置的可选参数,包括 attachmentsimages,它们会自动导致异步处理调用(以及 queued 响应)。如果您删除这些,您应该会看到返回给您的错误,其中应该突出显示子帐户不存在和无效 send_at 日期等问题。通常,您应该删除 所有 可选参数,除了您明确设置的参数。

此外,如果您使用的是模板(并使用发送模板发送),则无需在 html 参数中提供模板代码。如果您在 Mandrill 中存储的模板有 HTML,那将被忽略;如果存储的 Mandrill 模板还没有 HTML.

,您只需要提供 html

为了您和 Mandrill 的安全,由于 API 密钥被公开 post,它已被禁用,我编辑了原始 post 以将其删除。您应该生成另一个,而不是使用 post 此处编辑的那个。

把不用的参数全部删掉

try {
$mandrill = new Mandrill('API_KEY_REDACTED');
$template_name = 'Welcome mail on email /FB sign-up to very email id';
$template_content = array(
    array(
        'name' => 'Welcome mail on email /FB sign-up to very email id',
        'content' => 'sign-up'
    )
);
$message = array(
    'html' => '%TEMPLATE CODE%',
    'text' => 'Example text content',
    'subject' => 'Welcome to Easyaccom',
    'from_email' => 'hello@easyaccom.com',
    'from_name' => 'Easyaccom',
    'to' => array(
        array(
            'email' => 'RECIPIENT@gmail.com',
            'name' => 'Jordan Belfort',
            'type' => 'to'
        )
    ),
    'headers' => array('Reply-To' => 'message.reply@example.com'),
    'important' => false,
    'track_opens' => null,
    'track_clicks' => null,
    'auto_text' => null,
    'auto_html' => null,
    'inline_css' => null
    );
   $async = false;

$result = $mandrill->messages->sendTemplate($template_name, $template_content, $message, $async);
print_r($result);
/*
Array
(
    [0] => Array
        (
            [email] => recipient.email@example.com
            [status] => sent
            [reject_reason] => hard-bounce
            [_id] => abc123abc123abc123abc123abc123
        )

)
*/
} catch(Mandrill_Error $e) {
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
// A mandrill error occurred: Mandrill_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
throw $e;
  }
   ?>