<?php
	include "library.php";

	$send_it = val( $_GET, 'sendit' );

	if ($send_it <> "true")
		echo black( "TEST MODE<br><br>" );

	$cxn = start_code( true );


		/* kill the redirection of the email to the debugging address */
		/* if logged in as me */

	session_destroy();

// limit 1

	$query = "SELECT profile.* FROM profile WHERE email_address_valid = 'yes' and locked = 'no' and deleted = 'no' ORDER BY id DESC";

	$sent = date("Y-m-d H:i:s");

	$result = run_query( $query, $cxn );

	for ($i=0; $i < mysql_num_rows($result); $i++)
	{
		$data = get_row( $result );

		$subject = $_SESSION['sitename']." changes";

//		$text_body = "Dear ".name_case( $data['first_name'] )."\n\n";

		$text_body = "Dear Member\n\n";
		$text_body .= "We have made some changes to the website to make the pages clearer and easier to navigate.\n\n";
		$text_body .= "Our membership has now reached 3,612.\n\n";
		$text_body .= "If it has been a while since you last visited then please go to www.academicdating.net\n\n";
		$text_body .= "Regards\n";
		$text_body .= "\n";
		$text_body .= $_SESSION['sitename']."\n";
		$text_body .= "\n";

		$html_body = "Dear Member<br><br>";
		$html_body .= "We have made some changes to the website to make the pages clearer and easier to navigate.<br><br>";
		$html_body .= "Our membership has now reached 3,612.<br><br>";
		$html_body .= "If it has been a while since you last visited then please go to www.academicdating.net<br><br>";
		$html_body .= "<br>";
		$html_body .= "Regards<br>";
		$html_body .= "<br>";
		$html_body .= $_SESSION['sitename']."<br>";
		$html_body .= "<br>";

			/* don't include a web link or it will be classified as spam */

		if ($send_it == "true")
		{
				/* 2 == always redirect, 3 == never redirect */

			send_external( $data['id'], $subject, $text_body, $html_body, $cxn, 3 );

			$query2 = "INSERT INTO sys_message (sent_to_id, type, sent) VALUES (".$data['id'].", 'new_charges_not', '".$sent."')";
			$result2 = run_query( $query2, $cxn );
		}

// redirect for testing
		if ($i == 0)
			send_external( $data['id'], $subject, $text_body, $html_body, $cxn, 2 );

		echo black( "Email set to member ".$data['handle']."  Country ".$data['country']."<br>" );
	}

	echo black( "Emails sent: ".mysql_num_rows( $result ) );

	echo black( "<br>Finished" );

?>

