我正在创建一个管理区域,以便跟踪我的订阅者。我想要的是每次有人新订阅我的列表时显示和更新他们的电子邮件地址。如下所示,我希望电子邮件地址可以通过电子邮件发送。我确信我需要使用某种代码来获取订阅者信息并显示它,但我不知道从哪里获取它。我正在使用laravel包https://github.com/skovmand/mailchimp-laravel
这是我的mailchimp conbtroller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class MailChimpController extends Controller
{
public $mailchimp;
public $listId = '111111111';
public function __construct(\Mailchimp $mailchimp)
{
$this->mailchimp = $mailchimp;
}
public function manageMailChimp()
{
return view('mailchimp');
}
public function subscribe(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
]);
try {
$this->mailchimp
->lists
->subscribe(
$this->listId,
['email' => $request->input('email')]
);
return redirect()->back()->with('success','Email Subscribed successfully');
} catch (\Mailchimp_List_AlreadySubscribed $e) {
return redirect()->back()->with('error','Email is Already Subscribed');
} catch (\Mailchimp_Error $e) {
return redirect()->back()->with('error','Error from MailChimp');
}
}
}
这是我的admin.blade.php文件,我希望显示电子邮件地址。
@extends('layouts.app')
@section('content')
<div class="container">
<h1 class="text-center">Subscribers</h1>
<table class="table">
<thead>
<tr>
<th>Check</th>
<th>Email</th>
<th>City</th>
<th>Airport</th>
</tr>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</thead>
</table>
</div>
@endsection
如果我还有其他需要,请告诉我。任何帮助将不胜感激!
答案 0 :(得分:1)
为此,您需要访问MailChimp API。这是一个REST服务,因此您可以使用php-curl进行访问。
以下是一个例子:
public function getMailChimpList() {
$mailchimpId = "YOUR_MAILCHIMP_ID";
$listId = "LIST_ID";
$apiKey = "YOUR_API_KEY";
$mailchimpUrl = "https://us11.api.mailchimp.com/3.0";
//this url may be different, check your API endpoints
$url = $mailchimpUrl . '/lists//' . $listId . '/members/';
$header = 'Authorization: apikey ' . $apiKey;
return self::sendData($url, $header);
}
private static function sendData($url, $header) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($header, 'Content-Type: application/json'));
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = trim(curl_exec($curl));
curl_close($curl);
return $result;
}