gpt4 book ai didi

php - 使用 Mandrill (php) 发送电子邮件时出错

转载 作者:可可西里 更新时间:2023-10-31 22:53:16 27 4
gpt4 key购买 nike

我是第一次使用 mandrill api。我正在使用以下代码。我有 Mandrill API key 。

 <?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' => 'message.from_email@example.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'recipient.email@example.com',
'name' => 'Recipient Name'
)
),
'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,
'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);
print_r($result);

} catch(Mandrill_Error $e) {
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();

throw $e;
}
?>

通过使用此代码,我收到如下错误:

发生 Mandrill 错误:Mandrill_HttpError - API 调用消息/发送失败:错误设置证书验证位置:CAfile:/usr/local/share/certs/ca-root-nss.crt CApath:无

为什么会出现此错误?

最佳答案

在这个文件中: mandrill-api-php\src\Mandrill.php

在初始化 curl 的第 58 行:

$this->ch = curl_init();

您需要添加这两个选项来解决问题:

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);

或者您可以选择: HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK

关于php - 使用 Mandrill (php) 发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19222562/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com