使用Curl和PHP从Mailgun邮件列表中退订或删除用户

时间:2019-01-23 18:56:11

标签: php mailgun

我的订阅代码运行良好,但是我的取消订阅方法却不行。当用户在我的软件中关闭他的帐户时,我想将他从他可能所在的任何Mailgun邮件列表中删除。

这是我无法使用的内容:

<link rel="stylesheet" href="node_modules/mdi/css/materialdesignicons.min.css">
<link rel="stylesheet" href="node_modules/simple-line-icons/css/simple-line-icons.css">

当我查询列表时,当前用户仍显示为已订阅。我尝试过:

    $data = ["subscribed"=>False, 'address'=>$user->email, 'name'=>$user->name];
    $api_key = env('MAILGUN_SECRET');
    $listname = "mylist@mydomain.com";

    $options=['--user'=>'api:'.$api_key];
    $url = "https://api.mailgun.net/v3/lists/$listname/members";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, "api:".$api_key);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_POST, 1); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

    // Store the data:
    $result = curl_exec($curl);
    curl_close($curl);

,但是这些调整都没有使用户取消(或删除)用户。谁能告诉我我做错了什么? TIA!

更新:我确实通过指定全部三个来删除用户:

    "subscribed"=>"no"
    "subscribed"=>"False"
    $url = "https://api.mailgun.net/v3/lists/$listname/members/$user->email"; 
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); 

    curl_setopt($curl, CURLOPT_POST, 1); 
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

,但我也想取消订阅而不删除。 :)

0 个答案:

没有答案