我正在尝试使用mandrill api发送带有模板的电子邮件。我正在研究这里记录的方法:https://mandrillapp.com/api/docs/messages.php.html#method=send-template 代码在网址中实施: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;
}
?>
答案 0 :(得分:6)
您有很多未明确设置的可选参数,包括attachments
和images
,它们会自动导致调用异步处理(以及queued
响应)。如果删除它们,您应该看到返回给您的错误,这应该突出显示不存在的子帐户和无效的send_at
日期。通常,您应删除所有可选参数,但明确设置的参数除外。
此外,如果您正在使用模板(并使用send-template发送),则无需在html
参数中提供模板代码。如果您在Mandrill中存储的模板具有HTML,则会被忽略;如果存储的Mandrill模板还没有HTML,则只需提供html
。
为了您的安全,以及Mandrill,由于API密钥已公开发布,因此已被禁用,并且我已编辑原始帖子以将其删除。您应该生成另一个,而不是使用此处发布的那个。
答案 1 :(得分:0)
只需剪切所有未使用的参数
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;
}
?>