php – Mandrill ValidationError

栏目: PHP · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/17700002/mandrill-validationerror

非常高兴能在StackOverflow上提出我的第一个问题.这些年来,我一直在依靠它来教自己很多!

我的问题是这个.尝试通过Mandrill的API发送邮件时出现以下错误:

{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}

下面的代码是我用来尝试发送邮件的代码:

<?php
$to = 'their@email.com';
$content = '<p>this is the emails html <a href="www.google.co.uk">content</a></p>';
$subject = 'this is the 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;

?>

什么可能导致消息中的验证错误.我提供我的API密钥,它是有效的!

希望有人能够提供帮助,并感谢您在这里一般都很棒!

谢谢!

您可能还想使用数组,让 PHP 为您处理JSON编码.如果JSON由于某种原因无效,则此特定错误很常见.因此,例如,您可以像这样设置参数:

$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);

如果需要,您还可以使用json_decode来解析响应.

翻译自:https://stackoverflow.com/questions/17700002/mandrill-validationerror


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

规划算法

规划算法

拉瓦利 / 2011-1 / 99.00元

《规划算法》内容简介:规划是人类智慧的结晶,规划问题广泛地存在于人们的日常工作和生活中。现在,规划已涉及计算机科学、人工智能、力学、机械学、控制论、对策论、概率论、图论、拓扑学、微分几何、代数几何等许多现代科学领域。《规划算法》是作者多年来教学和科研工作的总结,系统地介绍了规划领域中的基础知识和最新成果。作者将三个相对独立的学科:机器人学、人工智能和控制论巧妙地结合在一起。《规划算法》给出了大量内......一起来看看 《规划算法》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试