<?php

#################################################################################
#               Mail function of the newsletter module 
# This function uses the mail() function from PHP if you want to use a different
# mail method you can replace the newsletter_mail function by your own.
# 
############################################################################
# mail_function.php: last changed 10/04/2006  , version: 1.0
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: mail_function.php,v 1.1 2006/10/03 10:33:58 fstuurman Exp $
############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

function newsletter_mail($email_list, $content, $owner_email, $subject)
{
	//the $email_list is an array with all the emails we are going to sent the newsletter
	//$email_list = ontains the actual emails as array
	//$content =  actual newsletter content, contains the link when send_link = 1
	//$owner_email = this is the email address of the of newsletter owner
	//$subject = contains the subject for the emails

	$content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
	<html>
	<head>
	  <meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\">
	  <title>$newsletter_name</title>
	</head><body>" . $content . "</body></html>";

	$headers = "From: $owner_email\r\n" .
	"Reply-To: $owner_email\r\n" .
	"X-Mailer: PHP/" . phpversion() . "\r\n" .
	"MIME-Version: 1.0\r\n" .
	"Content-Transfer-Encoding: 7bit\r\n" .
	"Content-type: text/html; charset=iso-8859-1\r\n";
	$number = count($email_list); //number of emails to process
	$i = 0;

	while ($i < $number)
	{
		set_time_limit(30);
		//print $email_list[$i]."<br>" ;
		mail($email_list[$i], $subject, $content, $headers);
		$i++;
	}
	return $number;
}
?>
