我正在使用Mandrill API发送电子邮件。
我已在Mandrill设置页面中注册了我的发送域名并正确设置了我的DKIM和SPF记录。
以下是我用于发送电子邮件的代码:
$template_name = "Test_Schedule_Reminder";
$to_email = "debesh@debeshnayak.com";
$to_name = "Test Email";
$from_email = "contact@debeshnayak.com";
$from_name = "Debesh Nayak";
require_once 'mandrill-api-php/src/Mandrill.php'; //Not required with Composer
try {
$mandrill = new Mandrill('my-mandrill-api-key');
$message = array(
'html' => $html_email_template,
'subject' => $email_title,
'from_email' => $from_email,
'from_name' => $from_name,
'to' => array(
array(
'email' => $to_email,
'name' => $to_name,
'type' => 'to'
)
),
'important' => true,
'track_opens' => true,
'track_clicks' => true,
'inline_css' => true,
'metadata' => array('website' => 'www.debeshnayak.com'),
);
$async = false;
$ip_pool = null;
$send_at = $utc_class_time;
$result = $mandrill->messages->send($message, $async, $ip_pool, $send_at);
print_r($result);
} 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;
}
当我从生产服务器发送邮件时,我可以发送电子邮件。
但是当我尝试从localhost发送电子邮件时,我收到以下错误:
Mandrill_HttpError - API call to messages/send failed: SSL certificate problem: unable to get local issuer certificate
因此,在使用Mandrill API测试来自localhost的邮件时,如何避免此SSL证书问题。
答案 0 :(得分:3)
检查Mandrill的库文件并搜索发送电子邮件的cURL
电话。检查此cURL的"CURLOPT_SSL_VERIFYPEER"
参数。将值设置为false
。它应该对你有帮助。
答案 1 :(得分:1)
我在call()
库文件的Mandrill.php
函数中添加了以下两行:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
现在,我可以使用localhost
从Mandrill API
发送电子邮件。