我正在尝试将一个api添加到我的网站,以允许用户订阅mailchimp列表。由于某些原因,我总是收到错误消息,而我只是无法弄清楚出什么问题了。 (我使用的是php 7,并且似乎在服务器上安装了Curl)。
错误
PHP Parse error: syntax error, unexpected '[', expecting ')' in subscribe.php on line 10
Subscribe.php
<?php
$email = 'email address';
$list_id = 'list id';
$api_key = 'api key';
$data_center = substr($api_key,strpos($api_key,'-')+1);
$url = 'https://'. $data_center .'.api.mailchimp.com/3.0/lists/'. $list_id .'/members';
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed', //pass 'subscribed' or 'pending'
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $api_key);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status_code;
?>