Nicholas Cheek

LITTLE ROCK WEB DEVELOPER

This will get the emails from the database and add them to a subscriber list in mailchimp.  Must include drewm Mailchimp Library

<?



	
set_time_limit(0);                   // ignore php timeout
ignore_user_abort(true);             // keep on going even if user pulls the plug*
$con=mysqli_connect("finneganmedicalsupply.com","root","finneganmedicalsupplies123","finn_live");

//-------------------------------------------------
//
// Check connection
//
//------------------------------------------------

	if (mysqli_connect_errno()) {
	  echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}

//-------------------------------------------------
//
// Include MailChimp Library
//
//------------------------------------------------
	//include our library
	require '/var/www/finneganmedicalsupply/public_html/MailChimp/MailChimp.php';
	//define the list we want to use
	$listID= "50d3a25c71";
	//start new instance of mailchimp
	$MailChimp = new \Nick\MailChimp('398233b58fd934f6582142570c3c86fb-us5');
	//define the date by the standard the db uses - WHY OH WHY
	//isn't this a datefield in the db?
	$dateMonth = date("m");
	$dateDay = date("d");
	$dateYear = date("Y");
//-------------------------------------------------
//
// Get list of past emails from database that were entered
// on the same date the script is running.
// (remove limit before it goes live)
//------------------------------------------------
 	$result = mysqli_query($con, "select distinct(cd.field_id_33)as email,cd.field_id_37 as FirstName, cd.field_id_43 as LastName, ct.month, ct.day, ct.year from finn_channel_data cd LEFT Join finn_channel_titles ct ON ct.entry_id = cd.entry_id where cd.channel_id = '3' AND ct.month ='". $dateMonth ."' AND ct.day = '". $dateDay ."' and ct.year = '". $dateYear ."'");
	

//-------------------------------------------------
//
// loop through to get results of each
//
//------------------------------------------------
	//make sure mysql returned rows
	if(mysqli_num_rows($result)>0){	
		//now start our loop
		while($row = mysqli_fetch_array($result)) {
	
//-------------------------------------------------
//
// Subscribe the new email addresses
// Using the mailchimp Library
//
//-------------------------------------------------

	
//print_r($row['email']);
	

$results = $MailChimp->call("lists/batch-subscribe", array(
"id"=> $listID, // required, the list id to pull abuse reports for (can be gathered using lists/list())
"batch" => array( // required, an array of structs for each address
array(
"email" => array( // required, a struct with one of the following keys
"email" => $row['email'] // an email address
),
"email_type" => "html", // optional, for the email type option (html or text)
"merge_vars" => array( // optional, data for the various list specific and special merge vars documented in lists/subscribe
)
)
),
"double_optin" => false, // optional, flag to control whether to send an opt-in confirmation email - defaults to true
"update_existing" => false, // optional, flag to control whether to update members that are already subscribed to the list or to return an error, defaults to false (return error)
"replace_interests" => true // optional, flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups
));

//used for debugging
//echo "<pre>";
//print_r($results['errors']['0']['error']);
//echo "</pre>";
}
}
//-------------------------------------------------
//
// Now let's grab the email address from the forms
// commented out because I believe they are going
// to use mailchimps form builder and insert it.
//-------------------------------------------------

//$form_results = mysqli_query($con, "SELECT email_address FROM finn_proform__newsletter_form WHERE updated BETWEEN CURDATE() - INTERVAL 1 DAY AND CURDATE()");

//while($row = mysqli_fetch_array($result)) {


//}

LITTLE ROCK WEB DEVELOPER

Living the dream.

nick@nicholascheek.com