Jump to content

[SOLVED] Net getting correct count


tgavin

Recommended Posts

I'm not getting the proper count. If I enter 3 email address in the form and click submit, the count is 3. Then, I fill out the form with one address and now the total count is 5 instead of 4. I'm sure it's because I'm setting $i=1, but if I don't, then a single address isn't counted.

 

// update counter page
function write_file($filename,$content) {
// let's make sure the file exists and is writable first.
if(is_writable($filename)) {
	// open the file in write mode so that we erase previous contents
	if(!$handle = fopen($filename, 'w')) {
		die("cannot open file: {$filename}");
	}
	// write $status to our opened file.
	if(fwrite($handle, $content) === FALSE) {
		die("cannot write to file: {$filename}");
	}
	// close the file
	fclose($handle);
	chmod($filename, 0644);
} else {
	die('Could not write to the file located at: '.$filename);
}
}

$emails = trim($_POST['email']);
$email = explode(',' , $emails);

$previous_count = file_get_contents('count.txt');

$i=1;
foreach($email as $to) {
$sent = mail($to,$subject,$message,$headers);
$i++;
}

$new_count = $previous_count + $i;

write_file('count.txt',$new_count);

Link to comment
https://forums.phpfreaks.com/topic/129971-solved-net-getting-correct-count/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.