我正在尝试使用 URL 中的名称、电子邮件和列表变量 Ping 一个 URL。经验:
https://myurl.com/?name=Example-Name&email=example@email.com&list=123456789hak。
所以我使用 $_GET 从 URL 中获取变量,然后想使用 POST 数组插入数据库。
代码似乎正确地抓取了变量,但数组插入失败。谁能看到我哪里出错了?
语言是PHP。这应该通过他们的 API 将联系人插入到 Sendy 中。
这是代码:
<?php
//-------------------------- You need to set these --------------------------//
$your_installation_url = 'https://myURL.com'; //Your Sendy installation (without the trailing slash)
$api_key = 'API CODE FOR THE DATABASE IS HERE'; //Can be retrieved from your Sendy's main settings
$success_url = 'http://google.com'; //URL user will be redirected to if successfully subscribed
$fail_url = 'http://yahoo.com'; //URL user will be redirected to if subscribing fails
//---------------------------------------------------------------------------//
//POST variables
$name = $_GET['name'];
$email = $_GET['email'];
$list = $_GET['list'];
$boolean = 'true';
//Check fields
if($name=='' || $email=='')
{
echo 'Please fill in all fields.';
exit;
}
//Subscribe
$postdata = http_build_query(
array(
'name' => $name,
'email' => $email,
'list' => $list,
'api_key' => $api_key,
'boolean' => 'true'
)
);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
$result = file_get_contents($your_installation_url.'/subscribe', false, $context);
//check result and redirect
if($result)
header("Location: $success_url");
else
header("Location: $fail_url");
?>
谢谢!