I've just started learning to code last week and the script I wrote over the weekend has stopped working.
It's just a simple script to use campaign monitors api to segment my list from distributors who have created a newly approved account, and distributors who have placed their first order.
Right now I just download an xls from the ecomm software (ultracart) of the days orders and turn it into a csv, run the script from wamp, using eclipse as my ide. Eventually I'll automate it but one thing at a time.
My laptop needed replaced this week, and I've tried to recreate the same environment I was using (I think I may have been using php 5.3 before now now 5.4) but when I try to run the script it's not functioning any longer.
If anybody is willing to take a glance at my code and maybe hint me in the right direction? I've tried dumping variables out, and they spit out the emails as it should, but it appears the values are null when I try to run the entire thing?
Also any mistakes or best practices I'm making I'm interested in correcting as well so if you see anything please point it out.
Here the script:
Here is the output (snipped the rest):
If anybody wants to chat on skype mine is joshk11.
Thanks for any help or input.
It's just a simple script to use campaign monitors api to segment my list from distributors who have created a newly approved account, and distributors who have placed their first order.
Right now I just download an xls from the ecomm software (ultracart) of the days orders and turn it into a csv, run the script from wamp, using eclipse as my ide. Eventually I'll automate it but one thing at a time.
My laptop needed replaced this week, and I've tried to recreate the same environment I was using (I think I may have been using php 5.3 before now now 5.4) but when I try to run the script it's not functioning any longer.
If anybody is willing to take a glance at my code and maybe hint me in the right direction? I've tried dumping variables out, and they spit out the emails as it should, but it appears the values are null when I try to run the entire thing?
Also any mistakes or best practices I'm making I'm interested in correcting as well so if you see anything please point it out.
Here the script:
Code:
<?php
require_once '/campaign_monitor/csrest_subscribers.php';
require_once '/campaign_monitor/csrest_general.php';
require_once 'cm_data.php'; // $apikey, $signup_list, $ordered_list, $signup_wrap, $ordered wrap
//set_time_limit( 240 );
define( 'CODE_INVALID_EMAIL', 1 );
define( 'CODE_EMAIL_NOT_FOUND', 203 );
$data = csv_to_array( 'orders.csv' );
$max = key( array_slice( $data, -1, 1, TRUE ) ); // sets max lines to csv check as last key in data array.
for ( $index = 0; $index <= $max; ++$index ) {
$work_email = $data[ $index ][ 'Email' ];
$get_result = $signup_wrap->get( $work_email ); // checks to see if email from csv is in the list
if ( $get_result->was_successful() ) {
$email = $get_result->response->EmailAddress;
$name = $get_result->response->Name;
echo "<b>Found A Match!!</b> </br>" . "Name " . $name . '</br>' . 'Email ' . $email . '</br>';
// Add the subscriber to ordered list
$add_result = $ordered_wrap->add(array(
'EmailAddress' => $email,
'Name' => $name,
'Resubscribe' => FALSE
));
if ( $add_result->was_successful() ) {
echo "Added $name to $ordered_list </br>";
} else {
echo 'Failed with code ' . $add_result->http_status_code."\n<br /><pre>";
var_dump ( $add_result->response );
echo '</pre>';
}
// Delete the subscriber from signup list
$del_result = $signup_wrap-> delete( $email );
if ( $del_result->was_successful() ) {
echo "Deleted $name from $signup_list </br>";
} else {
echo 'Failed with code ' . $del_result->http_status_code."\n<br /><pre>";
var_dump ( $del_result->response );
echo '</pre>';
}
continue;
}
if ( CODE_EMAIL_NOT_FOUND == $get_result->response->Code ) {
echo "<b>No Match </b></br>" . $data[$index]['Email'] . '</br>';
echo $get_result->response->Message . '</br>';
continue;
}
if( CODE_INVALID_EMAIL == $get_result->response->Code ) {
echo 'Invalid Email </br>';
continue;
}
}
// [url]https://gist.github.com/jaywilliams/385876[/url]
function csv_to_array($filename='', $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename))
return FALSE;
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 2000, $delimiter)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
Here is the output (snipped the rest):
If anybody wants to chat on skype mine is joshk11.
Thanks for any help or input.