我已经开始使用 Mandrill 从我们的站点发送所有邮件,但遇到了编码问题。
该网站的编码仍然是Windows1251 / CP-1251(我真的没有时间更改它)。我可以用英语发送电子邮件。但是当我尝试发送西里尔文电子邮件(乌克兰语、俄语等)时,它会显示一个错误“您必须指定一个键值......”。
我总是需要将电子邮件正文编码为 UTF-8。在这种情况下,Mandrill 可以很好地发送信件,但电子邮件的编码损坏。
有人知道是否可以使用 Windows-1251 字符集通过 Mandrill 发送电子邮件?我该如何解决?任何建议都会很有用!
代码如下:
require_once "all-sdk/mandrill/src/Mandrill.php";
$message_txt = utf8_encode($message);
try {
$mandrill = new Mandrill('my_api_key_here');
$message = array(
'html' => $message_txt,
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => 'fromemail@gmail.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'myemail@gmail.com',
'name' => 'Recipient Name',
'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->send($message, $async, $ip_pool, $send_at);
$result = $mandrill->messages->send($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;
}