问题描述
我第一次使用mandrill api。我正在使用以下代码。我有我的Mandrill API密钥。
<?php
try {
$ mandrill = new Mandrill('YOUR_API_KEY');
$ message = array(
'html'=>'< p>示例HTML内容< / p>',
'text'=>'示例文本内容',
'subject'=>'example subject',
'from_email'=>'[email protected]',
'from_name'=>'示例名称',
'to'=> array(
array(
'email'=>'[email protected]',
'name'=>'收件人姓名'
)
),
'headers'=>数组('Reply-To'=>'[email protected]'),
'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'=> '[email protected]',
'tracking_domain'=> null,
'signing_domain'=> null,
'return_path_domain'=> null,
'merge'=> true,
'global_merge_vars'=>数组(
数组(
'name'=>'merge1',
'content'=>'merge1内容'
)
),
'merge_vars'=> array(
array(
'rcpt'=>'[email protected]',
'vars'=> array(
array(
'name'=>'merge2',
'content'=>'merge2 content'
)
)
)
),
' tags'=> array('password-resets'),
'subaccount'=> 'customer-123',
'google_analytics_domains'=> array('example.com'),
'google_analytics_campaign'=> '[email protected]',
'metadata'=> array('website'=>'www.example.com'),
'recipient_metadata'=> array(
array(
'rcpt'=>'[email protected]',
'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 ='主池';
$ send_at ='example send_at';
$ result = $ mandrill-> messages-> send($ message,$ async,$ ip_pool,$ send_at);
print_r($ result);
} catch(Mandrill_Error $ e){
echo'发生mandrill错误:'。 get_class($ e)。 ' - '。 $ E->的getMessage();
throw $ e;
}
?>
通过使用此代码,我收到错误:
发生mandrill错误:Mandrill_HttpError - 对消息/发送的API调用失败:错误设置证书验证位置:CAfile:/usr/local/share/certs/ca-root-nss.crt CApath:none
为什么我得到这个错误?
错误表明您没有在本地安装所需的SSL证书,以验证与Mandrill API的SSL连接。您可以通过操作系统的软件包管理器获取一系列证书,也可以下载Mozilla发行的软件包:,然后将其存储在本地。
I am using mandrill api for the first time. I am using following code.I have Mandrill API Key with me.
<?php
try {
$mandrill = new Mandrill('YOUR_API_KEY');
$message = array(
'html' => '<p>Example HTML content</p>',
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => '[email protected]',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => '[email protected]',
'name' => 'Recipient Name'
)
),
'headers' => array('Reply-To' => '[email protected]'),
'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' => '[email protected]',
'tracking_domain' => null,
'signing_domain' => null,
'return_path_domain' => null,
'merge' => true,
'global_merge_vars' => array(
array(
'name' => 'merge1',
'content' => 'merge1 content'
)
),
'merge_vars' => array(
array(
'rcpt' => '[email protected]',
'vars' => array(
array(
'name' => 'merge2',
'content' => 'merge2 content'
)
)
)
),
'tags' => array('password-resets'),
'subaccount' => 'customer-123',
'google_analytics_domains' => array('example.com'),
'google_analytics_campaign' => '[email protected]',
'metadata' => array('website' => 'www.example.com'),
'recipient_metadata' => array(
array(
'rcpt' => '[email protected]',
'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);
print_r($result);
} catch(Mandrill_Error $e) {
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
throw $e;
}
?>
By using this code I am getting error as:
A mandrill error occurred: Mandrill_HttpError - API call to messages/send failed: error setting certificate verify locations: CAfile: /usr/local/share/certs/ca-root-nss.crt CApath: none
Why am I getting this error?
the error is indicating you don't have the required SSL cert installed locally to verify the SSL connection with Mandrill's API. You can get a bundle of certs through a package manager for your operating system, or you can download the bundle that's distributed with Mozilla: http://curl.haxx.se/docs/caextract.html and then store them locally.
这篇关于使用Mandrill(php)发送电子邮件时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!