* @link    		http://www.pioder.pl/
* @license	see LICENSE.txt
**/
if ( !defined('IN_uF') )
{
	die('Hacking attempt');
}
function SendEmail($email, $title, $content)
{
	global $forum_config;
	
	#headers
	$email_headers = "MIME-Version: 1.0\r\n";
	$email_headers .= "Content-type: text/html; charset=iso-8859-2\r\n";
	$email_headers .= "From: ".$forum_config['forumname']." \n";
	$email_date = date('d-m-Y, G:i',$_SERVER['REQUEST_TIME']);
	
	$email_content = '
	
	
	  '.$title.'
	
	
	  '.$content.'
	  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  
	  Message generated automatic by µForum ('.$email_date.')
	
	';
	
	#send email - do it!
	if ( !mail($email, $title, $email_content, $email_headers ))
	{
		message_die(GENERAL,'Could not send email from: '.$email.'. sorry :(','');
	}	
}
	
function SendRegisterEmail()
{
	global $forum_config;
	global $original_pass;
	global $lng;
	
	$email_content = $lng['email_newpasswd_msg'];
	$email_content = str_replace('%forum%',$forum_config['forumname'],$email_content);
	$email_content = str_replace('%url_f%',$forum_config['forumpatch'],$email_content);
	$email_content = str_replace('%ip%',$_SERVER['REMOTE_ADDR'],$email_content);
	$email_content = str_replace('%forum%',$forum_config['forumname'],$email_content);
	$email_content = str_replace('%login%',$_POST['nick'],$email_content);
	$email_content = str_replace('%pass%',$original_pass,$email_content);
	
	SendEmail($_POST['email'],$lng['email_welcome'].$forum_config['forumname'],$email_content);	
}
	
function SendForgotPassEmail($newpass)
{
	global $forum_config;
	global $original_pass;
	global $lng;
	global $uid;
	$email_content = $lng['email_register_msg'];
	$email_content = str_replace('%forum%',$forum_config['forumname'],$email_content);
	$email_content = str_replace('%url_f%',$forum_config['forumpatch'],$email_content);
	$email_content = str_replace('%ip%',$_SERVER['REMOTE_ADDR'],$email_content);
	$email_content = str_replace('%forum%',$forum_config['forumname'],$email_content);
	$email_content = str_replace('%login%',$_POST['username'],$email_content);
	$email_content = str_replace('%pass%',$newpass,$email_content);
	SendEmail(User::UserInformation($uid,'email'),$lng['email_sent_forget_pass'].$forum_config['forumname'],$email_content);
}
	
function SendMassEmail($title,$content)
{
   	$sql = "SELECT `email`,`u_id` FROM ".USERS_TABLE." WHERE `u_id`>0";
   	$query = DataBase::sql_query($sql,CRITICAL,'Could not read users table');
	while($item = DataBase::fetch($query))
	{
       		SendEmail($item['email'], $title, $content);
     	}
}	
?>