1

I am trying to Ping a URL with name, email, and list variable in the URL. Exp:

https://myurl.com/?name=Example-Name&email=example@email.com&list=123456789hak.

So I am using $_GET to grab the variables from the URL, and want to then insert into a database using a POST array.

The code seems to grab the variables correctly, but the array fails inserting. Can anybody see where I am going wrong?

Language is PHP. This is supposed to insert contacts into Sendy via their API.

Here is the code:

<?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");

?>

Thanks!

Veit
  • 49
  • 2
  • 9

0 Answers0