Mailjet:将电子邮件添加到列表不起作用 [英] Mailjet: Adding email to list does not work
问题描述
我已经开始使用Mailjet通过表单存储订阅电子邮件。我用于此任务的库是 https://github.com/mailjet/mailjet- apiv3-php-simple
I have started to use Mailjet to store the subscription emails using a form. The library I used for this task is "https://github.com/mailjet/mailjet-apiv3-php-simple"
include("php-mailjet-v3-simple.class.php");
$apiKey = "xxx";
$secretKey = "yyy";
$mj = new Mailjet($apiKey, $secretKey);
$contact_params = array("method" => "POST", "Email" => "abc@gmail.com");
$contact = $mj->contact($contact_params);
$add_params = array(
"method" => "POST",
"ListID" => "11223344",
"IsActive" => "True"
);
$result = $mj->listrecipient($add_params);
但是此方法不会将电子邮件添加到Mailjet列表中。我在这里做错了什么?请帮助我。
But this method does not add the email to the Mailjet list. What did I do wrong here? Please help me.
推荐答案
编辑:
请参见此答案(如果您使用的是低于5.4的PHP版本,则为修复程序。
See the edits on this answer for a fix if you are using a PHP version older than 5.4.
如果可能,请尝试升级:-)
If possible, try to upgrade instead :-)
首先,感谢您对Mailjet的关注!
First of all, thank you for your interest in Mailjet!
现在,在为您提供答案之前,请先了解您所要求的指南这里 :-)。
另外,该库的Github存储库具有关于联系人和联系人列表的示例部分。
Now, before giving you the answer, please know that there is a guide for what you're asking here :-) .
Also, the README for the Github repo for that library has an example section on contacts and contactslists.
现在,您知道下次遇到此库的问题时,应该先查找哪里,例如马上解决,是吗? ;-)
Now that you know where to first look the next time you have issues with this library, let's get to the fix, shall we? ;-)
您的 add_Params
数组只需要一个 ContactID
字段。
它应该是这样的:
Your add_Params
array simply needs a ContactID
field.
Here is what it should look like:
$add_params = [
"method" => "POST",
"ListID" => [TheListID],
"ContactID" => [TheContactID],
"IsActive" => True
];
这应该可以解决您的问题。
This should solve your issue.
请继续阅读以了解原因。
此外,创建联系人并将其添加到最后描述的新列表的全过程。
Read on if you want to know why.
Also, full process of creating a contact and adding it to a new list described at the end.
列表收件人
资源是将联系人
资源链接到 contactslist
资源。
,这意味着在创建 listrecipient
资源时,API不知道要做什么。没有所有必要的参数(有关此处的详细信息)。
The listrecipient
resource is a way to link a contact
resource to a contactslist
resource.
Which means that the API doesn't know what to do when you create a listrecipient
resource without all the necessary parameters (more info on that here).
让我们创建一个联系人
和一个 contactslist
资源并将前者添加到后者。
(我假设您有 $ mj
实例, c $ c> Mailjet 类。)
Let's create a contact
and a contactslist
resources and add the former to the latter.
(I assume that you have a $mj
instance of the Mailjet
class.)
请确保联系您正在尝试创建ha尚未创建。
有关更多信息,请参见此处。
Make sure that the contact you're trying to create hasn't already been created.
See here for more infos.
$makeContactParams = [
"method" => "POST",
"Email" => "testSO@example.org"
];
$contact = $mj->contact($makeContactParams);
echo "Contact ID: ".$contact->Data[0]->ID."\n";
$contactslistParams = [
"method" => "POST",
"Name" => "TestSO"
];
$list = $mj->contactslist($contactslistParams);
echo "List ID: ".$list->Data[0]->ID."\n\n";
$listRecepParams = [
"method" => "POST",
"ListID" => $list->Data[0]->ID,
"ContactID" => $contact->Data[0]->ID,
"IsActive" => True
];
$recep = $mj->listrecipient($listRecepParams);
我希望这可以帮助您解决问题并理解为什么它首先出现在这里:-)
I hope this helped you solve your problem and understand why it was there in the first place :-)
这篇关于Mailjet:将电子邮件添加到列表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!