Mail Jet插件-扩展功能和重用API

时间:2016-10-16 作者:jbo

起初,我使用经典的apache sendmail从自定义表单发送电子邮件。最后,我决定使用Mailjet发送所有内容:表单提交和事务性电子邮件。我安装了插件,效果很好。

由于Mailjet API是通过插件安装的,我想依靠插件来发送新闻稿订阅和取消订阅,以及发送自动触发器。

我查看文档:https://dev.mailjet.com/guides/#contactslist_managemanycontacts请注意,我无法使用:

$apikey = get_option(\'mailjet_password\');

$apisecret = get_option(\'mailjet_username\');

我尝试使用ajax和类似于API文档的函数,但似乎不起作用:

function sendRegisterNewsletter($list_id, $email, $firstname, $name, $job, $structure) {

$apikey = get_option(\'mailjet_password\');
$apisecret =  get_option(\'mailjet_username\');

require \'../../plugins/mailjet-for-wordpress/api/mailjet-api-v3.php\';
use \\Mailjet\\Resources;
$mj = new \\Mailjet\\Client($apikey, $apisecret);

}
“use”出现错误:语法错误,意外的T\\u use use

当我使用插件时,我认为使用模块没有什么用处:https://github.com/mailjet/mailjet-apiv3-php

对于使用配置好的插件和Mailjet的api有什么建议吗?提前感谢您的帮助。

jb公司

1 个回复
SO网友:jbo

因为模板是在插件之前加载的,所以我最终决定直接从https://github.com/mailjet/mailjet-apiv3-php-no-composer

我检查api:https://dev.mailjet.com/guides/?php#contactslist_managemanycontacts

并构建我的函数将联系人发送到列表:

// Get the value from the plugin mailjet-for-wordpress
$apisecret = get_option(\'mailjet_password\');
$apikey = get_option(\'mailjet_username\');

require \'mailjet-apiv3-php-no-composer/vendor/autoload.php\';

use \\Mailjet\\Resources;

function sendRegisterNewsletterToMailjet($params) {

$mj = new \\Mailjet\\Client($apikey, $apisecret);

$body = [
\'Action\' => "addforce",
\'Contacts\' => [
[
\'Email\' => $params[\'Email\'],
\'Properties\' => [
\'prénom\' => $params[\'prénom\'],
\'nom\' => $params[\'nom\'],
\'profession\' => $params[\'profession\'],
\'structure\' => $params[\'structure\'],
]
],
]
];

$response = $mj->post(Resources::$ContactslistManagemanycontacts, [\'id\' => $params[\'ListID\'], \'body\' => $body]);
$response->success() && var_dump($response->getData());

wp_send_json_success($response);

}
问题是我得到了这样的回答:

{
    "success":true,
    "data":
        {
            "request":{
            "type":"application/json"
        }
    }
}
而不是:

{
    "Count": 1,
    "Data": [
        {
            "JobID": 35800
        }
    ],
    "Total": 1
}
有什么想法吗?