2016-02-16 66 views
0

我正在使用Mandrill API发送电子邮件。为什么Mandrill电子邮件不是从开发服务器(localhost)发送的?

我已经注册了我的发送域,并在Mandrill设置页面中正确设置了我的DKIM和SPF记录。

以下是我的代码被用于发送电子邮件:

$template_name = "Test_Schedule_Reminder"; 
$to_email = "[email protected]"; 
$to_name = "Test Email"; 

$from_email = "[email protected]"; 
$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; 
} 

我能够发送电子邮件时,我从我的生产服务器发送。

但是,当我试图从本地主机,我收到以下错误发送电子邮件:

Mandrill_HttpError - API call to messages/send failed: SSL certificate problem: unable to get local issuer certificate 

所以从本地主机使用山魈API测试邮件时如何避免此SSL证书问题。

+0

检查Mandrill的库文件并检查发送电子邮件的cURL调用。然后检查它的“CURLOPT_SSL_VERIFYPEER”参数。将值设置为false。它应该帮助你。 –

+0

谢谢@GokulShinde。您的回复帮助我解决了这个问题。 –

+0

欢迎。添加它作为答案。接受它,并upvote。 –

回答

2

检查Mandrill的库文件并检查cURL发送电子邮件的调用。然后检查"CURLOPT_SSL_VERIFYPEER"参数。将值设为false。它应该帮助你。

0

我已经添加了以下两个行内Mandrill.php库文件的call()功能:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 

现在我能够从我的localhost使用Mandrill API发送电子邮件。

相关问题