I've read through the discussions related to my topic and still am in need of assistance. When I enter an email into the signup in my footer, I receive the "Invalid Resource" error. website www.michaelmagrin.com
The HTML for the portion of the site is:
<h5>CONTACT</h5>
<form id="widget-subscribe-form" action="include/subscribe.php" method="post" class="nobottommargin">
<div class="input-group divcenter">
<div class="input-group-prepend">
<div class="input-group-text"><i class="icon-email2"></i></div>
</div>
<input type="email" id="widget-subscribe-form-email" name="widget-subscribe-form-email" class="form-control required email" placeholder="Enter your Email">
<div class="input-group-append">
<button class="btn btn-success" type="submit">Subscribe</button>
</div>
</div>
</form>
The PHP subscribe file is:
<?php
error_reporting(E_ALL);
$apiKey = '6211ba00ce05520f2f641d3d6b4cf05d-us3'; // Your MailChimp API Key
$listId = '4be0e81e19'; // Your MailChimp List ID
if( isset( $_GET['list'] ) AND $_GET['list'] != '' ) {
$listId = $_GET['list'];
}
$email = $_POST['widget-subscribe-form-email'];
$fname = isset( $_POST['widget-subscribe-form-fname'] ) ? $_POST['widget-subscribe-form-fname'] : '';
$lname = isset( $_POST['widget-subscribe-form-lname'] ) ? $_POST['widget-subscribe-form-lname'] : '';
$datacenter = explode( '-', $apiKey );
$submit_url = "https://" . $datacenter[1] . ".api.mailchimp.com/3.0/lists/" . $listId . "/members/" ;
if( isset( $email ) AND $email != '' ) {
$merge_vars = array();
if( $fname != '' ) { $merge_vars['FNAME'] = $fname; }
if( $lname != '' ) { $merge_vars['LNAME'] = $lname; }
$data = array(
'email_address' => $email,
'status' => 'subscribed'
);
$data['merge_fields'] = $merge_vars;
$payload = json_encode($data);
$auth = base64_encode( 'user:' . $apiKey );
$header = array();
$header[] = 'Content-type: application/json; charset=utf-8';
$header[] = 'Authorization: Basic ' . $auth;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result);
if ( isset( $data->status ) AND $data->status == 'subscribed' ){
echo '{ "alert": "success", "message": "You have been **successfully** subscribed to our Email List." }';
} else {
echo '{ "alert": "error", "message": "' . $data->title . '" }';
}}
?>
