2016-07-20 60 views
0

我使用山魈API但得到error:Undefined property: Mandrill::$messages.code:

$mandrill = new Mandrill('My KEY');   
    $message = array(
     'subject' => 'My subject', 
     'from_email' => '[email protected]', 
     'to' => array(array('email' => '[email protected]', 'name'=> 'Marc')), 
     'merge_vars' => array(array(
      'rcpt' => '[email protected]', 
      'vars' => 
      array(
       array(
        'name' => 'FIRSTNAME', 
        'content' => 'Recipient 1 first name'), 
       array(
        'name' => 'LASTNAME', 
        'content' => 'Last name') 
     )))); 

    $template_name = 'Lodging Connection'; 

    $template_content = array(
     array(
      'name' => 'main', 
      'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, thanks for signing up.'), 
     array(
      'name' => 'footer', 
      'content' => 'Copyright 2013.') 

    );   
    $response = $mandrill->messages->send($template_name, $template_content, $message); 
    print_r($response); 
+0

是'$ message = array()'不應該是'$ messages = array()'?或者將'$ mandrill-> messages-> send()'改爲'$ mandrill-> message-> send()' –

回答

1

對於模板發送消息,你應該使用sendTemplate,而不是send

$response = $mandrill->messages->sendTemplate($template_name, $template_content, $message); 
+0

thnxs這對我有效,但是我怎樣才能通過API在模板中添加內容? – RamanSall

+0

嘗試[這些](https://www.mandrillapp.com/api/docs/templates.php.html#method=update)功能。如果你仍然堅持嘗試作爲一個單獨的問題。 –

+0

如果解決了原始問題,也請將答案標記爲已接受 –