php - Mandrill ValidationError -


very excited asking first question on stackoverflow. i've been relying on teach myself quite lot on years!

my question this. getting following error when trying send mail through mandrill's api:

{"status":"error","code":-1,"name":"validationerror","message":"you must specify key value"} 

the code follows using try send mail:

<?php $to = 'their@email.com'; $content = '<p>this emails html <a href="www.google.co.uk">content</a></p>'; $subject = 'this subject'; $from = 'my@email.com';  $uri = 'https://mandrillapp.com/api/1.0/messages/send.json'; $content_text = strip_tags($content);  $poststring = '{ "key": "rr_3ytmxxxxxxxx_pa7gq", "message": {   "html": "' . $content . '",  "text": "' . $content_text . '",  "subject": "' . $subject . '",  "from_email": "' . $from . '",  "from_name": "' . $from . '",  "to": [  {  "email": "' . $to . '",  "name": "' . $to . '"  }  ],  "track_opens": true,  "track_clicks": true,  "auto_text": true,  "url_strip_qs": true,  "preserve_recipients": true }, "async": false }';  $ch = curl_init(); curl_setopt($ch, curlopt_url, $uri); curl_setopt($ch, curlopt_followlocation, true ); curl_setopt($ch, curlopt_returntransfer, true ); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $poststring); $result = curl_exec($ch); echo $result;  ?> 

what causing validation error in message. providing api key, , it's valid!

hope able help, , being awesome here!

thanks!

you may want use arrays, , let php handle json encoding you. particular error common if json invalid reason. so, example, set parameters this:

$params = array(     "key" => "keyhere",     "message" => array(         "html" => $content,         "text" => $content_text,         "to" => array(             array("name" => $to, "email" => $to)         ),         "from_email" => $from,         "from_name" => $from,         "subject" => $subject,         "track_opens" => true,         "track_clicks" => true     ),     "async" => false );  $poststring = json_encode($params); 

you can use json_decode parse response if needed.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -