Location: PHPKode > projects > MGB OpenSource Guestbook > email.php
<?php
	/*
	MGB 0.6.x - OpenSource PHP and MySql Guestbook
	Copyright (C) 2004 - 2011 Juergen Grueneisl - http://www.m-gb.org/

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
	*/

	// ========= //
	// email.php //
	// ========= //
	//
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	// show all errors
	error_reporting(E_ALL & ~E_NOTICE);

	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Datum in der Vergangenheit

	$site_name = "email.php";

	// load config, settings, language files and necessary templates
	require ("includes/functions.inc.php");
	// check if MGB has been already installed or updated
	mgb_iou_check("");
	require ("includes/config.inc.php");
	require ("includes/load_settings.inc.php");
	require ("language/".$settings['language_path']."/lang_main.php");
	require ("language/".$settings['language_path']."/settings.php");

	// ============
	$settings['wrong_captcha_count'] = "3";			// durch richtige settings ersetzen
	// ============

	// set timezone
	date_default_timezone_set($settings['timezone']);

	if($settings['banlist_ips'] == 1)
		{
		if(mgb_check_banlist_ips($_SERVER['REMOTE_ADDR'], $settings['blocktime']) == TRUE)
			{
			echo "<b>ERROR</b><br><br>You have been banned 'til hell freezes!<br><br>If this is a mistake, please contact the Administrator of this website.";
			if(isset($settings['spam_mail']) AND $settings['spam_mail'] != "")
				{
				$header = 'Content-Type: text/html; charset='.$charset."\r\n".'From: '.$settings['admin_gbemail']."\r\n".'Reply-To: '.$settings['spam_mail']."\r\n".'X-Mailer: PHP/'.phpversion();
				$caption = "email.php: ".$_SERVER['REMOTE_ADDR']." kam wieder!";
				$mailtext = $_SERVER['REMOTE_ADDR']." Wurde erfolgreich durch die permanente Blockliste abgewehrt!<br><br>\n\n";
				$mailtext.= "IP: ".$_SERVER['REMOTE_ADDR']."<br>\n";
				$mailtext.= "User-Agent: ".$_SERVER['HTTP_USER_AGENT'];
				if(!mail($settings['spam_mail'], $caption, $mailtext, $header))
					{
					echo "<br>Script is unable to send mail to administrator.";
					}
				}
			if(isset($settings['banlist_log']) AND $settings['banlist_log'] != "")
				{
				mgb_sql_connect("INSERT INTO ".$db['prefix']."spam_log (
					ID ,
					ip ,
					email ,
					user_agent ,
					message ,
					type ,
					site ,
					timestamp
					) values (
					NULL ,
					'".$_SERVER['REMOTE_ADDR']."' ,
					'' ,
					'".$_SERVER['HTTP_USER_AGENT']."' ,
					'' ,
					'1' ,
					'".$site_name."' ,
					'".time()."')", "ERROR while saving data into spam_log.", 0);
				}
			die();
			}
		}

	// load general templates
	$content_header = mgb_load_template("user", $settings['template_path'], "general/header");
	$content_footer = mgb_load_template("user", $settings['template_path'], "general/footer");
	$content_copyright = mgb_load_template("user", $settings['template_path'], "general/copyright");
	$content_scrolling_function = mgb_load_template("user", $settings['template_path'], "general/scrolling_function");
	$content_errormessage = mgb_load_template("user", $settings['template_path'], "general/errormessage");
	$content_captcha = mgb_load_template("user", $settings['template_path'], "general/captcha");
	// load main templates
	$content_email_body = mgb_load_template("user", $settings['template_path'], "main/email_body");
	$content_email_body_success = mgb_load_template("user", $settings['template_path'], "main/email_body_success");
	$content_email_user_accept_akismet_service = mgb_load_template("user", $settings['template_path'], "main/email_user_accept_akismet_service");

	$captcha_generated = 0;

	// check if user has too many counts in trying to make a guestbook entry or sending an email
	$result = mgb_sql_connect("SELECT COUNT(ID) FROM ".$db['prefix']."spam", "Error while counting entries in spam table.", 1);
	$total = @mysql_result($result, 0);

	$result = mgb_sql_connect("SELECT id, ip, email, counter, timestamp FROM ".$db['prefix']."spam", "Error while loading entries from spam table.", 1);

	for ($i = 0; $i < $total; $i++)
		{
		$spam[$i] = mysql_fetch_array($result);
		if($_SERVER['REMOTE_ADDR'] == $spam[$i]['ip'])
			{
			$counter = $spam[$i]['counter'];
			if($counter == 5)
				{
				if($settings['blocktime'] != 9999999)
					{
					$blocktime = time() - $spam[$i]['timestamp'];
					// 99999999 = forever
					// 6480000 = 1 month
					// 216000 = 1 day
					// 3600 = 1 hour
					// 60 = 1 minute
					// 0 = never
					if($blocktime <= $settings['blocktime'])
						{
						$rest = $settings['blocktime'] - $blocktime;
						echo "<b>ERROR</b><br><br>Due to some reason you have been blocked. Wait ".$rest." more seconds.<br><br>ifthis is a mistake, please contact the Administrator of this website.";
						$header = 'Content-Type: text/html; charset='.$charset."\r\n".'From: '.$settings['admin_gbemail']."\r\n".'Reply-To: '.$settings['spam_mail']."\r\n".'X-Mailer: PHP/'.phpversion();
						$caption = "email.php: ".$_SERVER['REMOTE_ADDR']." kam wieder!";
						$mailtext = $_SERVER['REMOTE_ADDR']." ist geblockt und hat nochmal versucht das G&auml;stebuch zu erreichen!<br><br>\n\n";
						$mailtext.= "IP: ".$_SERVER['REMOTE_ADDR']."<br>\n";
						$mailtext.= "User-Agent: ".$_SERVER['HTTP_USER_AGENT'];
						mail($settings['spam_mail'], $caption, $mailtext, $header);
						die();
						}
					}
				else
					{
					echo "<b>ERROR</b><br><br>You have been banned 'til hell freezes!<br><br>If this is a mistake, please contact the Administrator of this website.";
					$header = 'Content-Type: text/html; charset='.$charset."\r\n".'From: '.$settings['admin_gbemail']."\r\n".'Reply-To: '.$settings['spam_mail']."\r\n".'X-Mailer: PHP/'.phpversion();
					$caption = "email.php: ".$_SERVER['REMOTE_ADDR']." kam wieder!";
					$mailtext = $_SERVER['REMOTE_ADDR']." ist geblockt und hat nochmal versucht das G&auml;stebuch zu erreichen!<br><br>\n\n";
					$mailtext.= "IP: ".$_SERVER['REMOTE_ADDR']."<br>\n";
					$mailtext.= "User-Agent: ".$_SERVER['HTTP_USER_AGENT'];
					mail($settings['spam_mail'], $caption, $mailtext, $header);
					die();
					}
				}
			}
		}

	// load user data
	if ($_GET['id'] == "denied")
		{
		$errorcode = 8;
		$_POST['sent'] = 1;
		}
	elseif ($_GET['id'] != "admin")
		{
		$result = mgb_sql_connect("SELECT name, email, user_show_email FROM ".$db['prefix']."entries WHERE id=".secure_value($_GET['id']), "Error while loading information about user.", 1);
		$sendemail = @mysql_fetch_array($result);

		$sendemail_name = $sendemail['name'];
		$sendemail_email = $sendemail['email'];
		$sendemail_user_show_email = $sendemail['user_show_email'];

		if ($sendemail_user_show_email == 0) { $errorcode = 8; $_POST['sent'] = 1; }
		}
	else
		{
		$sendemail_email = $settings['admin_email'];
		$sendemail_name = $settings['admin_name'];
		}

	if (isset($_POST['sent']) AND $_POST['sent'] == 1)
		{
		// delete html, php code and white spaces
		
		if(!isset($_POST['user_sendcopytome'])) { $_POST['user_sendcopytome'] = 0; }
		if(!isset($_POST['name'])) { $_POST['name'] = NULL; }
		if(!isset($_POST['email'])) { $_POST['email'] = NULL; }
		if(!isset($_POST['message'])) { $_POST['message'] = NULL; }
		
		$_POST['name'] = cleanstr($_POST['name']);
		$_POST['email'] = cleanstr($_POST['email']);
		$_POST['message'] = cleanstr($_POST['message']);
		$_POST['user_sendcopytome'] = cleanstr($_POST['user_sendcopytome']);

		// include akismet if it exists
		if (file_exists("plugins/akismet/akismet.class.php") AND (isset($settings['akismet_api'])) AND ($settings['akismet_api'] != "") AND (isset($_POST['user_accept_akismet_service']) AND $_POST['user_accept_akismet_service'] == 1) AND ($_POST['name'] != "") AND ($_POST['email'] != "") AND ($_POST['message'] != ""))
			{
			include ("plugins/akismet/akismet.class.php");

			$akismet_author = bbcode_delete($_POST['name']);
			$akismet_email = bbcode_delete($_POST['email']);
			$akismet_website = bbcode_delete($_POST['hp']);
			$akismet_body = bbcode_delete($_POST['message']);

			// check for spam
			// Load array with comment data.
			$comment = array(
				'author' => $akismet_author,
				'email' => $akismet_email,
				'website' => $akismet_website,
				'body' => $akismet_body,
				'permalink' => 'http://'.$settings['h_domain'].$settings['gb_path'],
				'user_ip' => $_SERVER['REMOTE_ADDR'], // Optional, if not in array defaults to $_SERVER['REMOTE_ADDR'].
				'user_agent' => $_SERVER['HTTP_USER_AGENT'], // Optional, if not in array defaults to $_SERVER['HTTP_USER_AGENT'].
				);

			// Instantiate an instance of the class.
			$akismet = new Akismet('http://'.$settings['h_domain'].$settings['gb_path'], $settings['akismet_api'], $comment);

			// Test for errors.
			if($akismet->errorsExist())
				{ // Returns true if any errors exist.
				if($akismet->isError('AKISMET_INVALID_KEY'))
					{
					echo "AKISMET API KEY INVALID";
					}
				elseif($akismet->isError('AKISMET_RESPONSE_FAILED'))
					{
					echo "AKISMET RESPONSE FAILED";
					}
				elseif($akismet->isError('AKISMET_SERVER_NOT_FOUND'))
					{
					echo "AKISMET_SERVER_NOT_FOUND";
					}
				}
			else
				{
				// No errors, check for spam.
				if($akismet->isSpam())
					{
					// ifis set in the admin panel, mark the entry as spam
					if(isset($settings['akismet_mark_as_spam']) AND ($settings['akismet_mark_as_spam'] == 1))
						{
						$tracker = 0;
						for ($i = 0; $i < $total; $i++)
							{
							if($_SERVER['REMOTE_ADDR'] == $spam[$i]['ip'] OR $_POST['email'] == $spam[$i]['email'])
								{
								$counter = $spam[$i]['counter'];
								if($counter <= 5)
									{
									$counter = $counter + 1;
									if(mgb_sql_connect("UPDATE `".$db['prefix']."spam` SET `counter` = '".$counter."', `timestamp` = '".time()."' WHERE ID='".$spam[$i]['id']."' LIMIT 1", "Error while saving data into ".$db['prefix']."spam", 0))
										{
										$type = 4; // 5 = Update durch Akismet
										mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], $counter, $spam[$i]['id'], $_POST['message'], $site_name, $type);
										}
									}
								$tracker++;
								}
							}
						if($tracker == 0)
							{
							if(mgb_sql_connect("INSERT INTO ".$db['prefix']."spam (
								name,
								ip,
								email,
								city,
								icq,
								aim,
								msn,
								hp,
								message,
								user_notification,
								user_show_email,
								captcha,
								sent_captcha,
								counter,
								timestamp
								) values (
								'".cleanstr($_POST['name'])."',
								'".cleanstr($_SERVER['REMOTE_ADDR'])."',
								'".cleanstr($_POST['email'])."',
								'".cleanstr($_POST['city'])."',
								'".cleanstr($_POST['icq'])."',
								'".cleanstr($_POST['aim'])."',
								'".cleanstr($_POST['msn'])."',
								'".cleanstr($_POST['hp'])."',
								'".cleanstr($_POST['message'])."',
								'".cleanstr($_POST['user_notification'])."',
								'".cleanstr($_POST['user_show_email'])."',
								'".$captcha_code."',
								'".cleanstr($_POST['captcha'])."',
								'1',
								'".time()."'
								)", "Error while saving data into ".$db['prefix']."spam", 0))
									{
									$type = 3; // 3 = Neueintrag durch Akismet
									mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], "", "", $_POST['message'], $site_name, $type);
									}
							die();
							}
						}
					else
						{
						$mark_as_spam = 0;
						$noemail = 0;
						}
					}
				}
			}

		// check email and ip with banlists
		if($settings['banlist_mails'] == 1)
			{
			if (mgb_check_banlist_mails($_POST['email'], $settings['blocktime']) == TRUE) { $errorcode = 12; $block_code = 1; }
			}
		if($settings['banlist_domains'] == 1)
			{
			if (mgb_check_banlist_domains($_POST['email'], $settings['blocktime']) == TRUE) { $errorcode = 13; $block_code = 2; }
			}
		if($settings['banlist_ips'] == 1)
			{
			if (mgb_check_banlist_ips($_SERVER['REMOTE_ADDR'], $settings['blocktime']) == TRUE) { $errorcode = 14; $block_code = 3; }
			}

		// form was sent and is ok!
		if($errorcode == 0)
			{
			// check if captcha is correct
			if ($settings['captcha'] == 1)
				{
				if ($settings['captcha_method'] == 0)
					{
					if($_POST['captcha'] != "") // captcha is not empty
						{
						$result = mgb_sql_connect("SELECT `code` FROM ".$db['prefix']."captcha LIMIT 1", "Error while checking ifcaptcha is correct.", 1);
						$saved_code = @mysql_fetch_array($result);
						$captcha_code = $saved_code['code'];
						if($captcha_code != $_POST['captcha']) // captcha is wrong
							{
							$errorcode = 7; // captcha is not empty, it's invalid
							$tracker = 0;
							for ($i = 0; $i < $total; $i++)
								{
								if($_SERVER['REMOTE_ADDR'] == $spam[$i]['ip'] OR $_POST['email'] == $spam[$i]['email'])
									{
									$counter = $spam[$i]['counter'];
									if($counter <= 5)
										{
										$counter = $counter + 1;
										if(mgb_sql_connect("UPDATE `".$db['prefix']."spam` SET `counter` = '".$counter."', `timestamp` = '".time()."' WHERE ID='".$spam[$i]['id']."' LIMIT 1", "Error while saving data into ".$db['prefix']."spam", 0))
											{
											$type = 6; // 6 = Update durch falsch eingegebenes Captcha
											mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], $counter, $spam[$i]['id'], $_POST['message'], $site_name, $type);
											}
										}
									$tracker++;
									}
								}
							if($tracker == 0)
								{
								if(mgb_sql_connect("INSERT INTO ".$db['prefix']."spam (
									name,
									ip,
									email,
									city,
									icq,
									aim,
									msn,
									hp,
									message,
									user_notification,
									user_show_email,
									captcha,
									sent_captcha,
									counter,
									timestamp
									) values (
									'".cleanstr($_POST['name'])."',
									'".cleanstr($_SERVER['REMOTE_ADDR'])."',
									'".cleanstr($_POST['email'])."',
									'".cleanstr($_POST['city'])."',
									'".cleanstr($_POST['icq'])."',
									'".cleanstr($_POST['aim'])."',
									'".cleanstr($_POST['msn'])."',
									'".cleanstr($_POST['hp'])."',
									'".cleanstr($_POST['message'])."',
									'".cleanstr($_POST['user_notification'])."',
									'".cleanstr($_POST['user_show_email'])."',
									'".$captcha_code."',
									'".cleanstr($_POST['captcha'])."',
									'1',
									'".time()."'
									)", "Error while saving data into ".$db['prefix']."spam", 0))
									{
									$type = 5; // 5 = Neueintrag durch falsch eingegebenes Captcha
									mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], "", "", $_POST['message'], $site_name, $type);
									}
								}
							}
						else // captcha is valid
							{
							for ($i = 0; $i < $total; $i++)
								{
								if($_SERVER['REMOTE_ADDR'] == $spam[$i]['ip'] OR $_POST['email'] == $spam[$i]['email'])
									{
									$counter = $spam[$i]['counter'];
									if($counter <= 5)
										{
										$counter = $counter + 1;
										if(mgb_sql_connect("UPDATE `".$db['prefix']."spam` SET `counter` = '".$counter."', `timestamp` = '".time()."' WHERE ID='".$spam[$i]['id']."' LIMIT 1", "Error while saving data into ".$db['prefix']."spam", 0))
											{
											$type = 7; // 7 = Update durch richtig eingegebenes Captcha (Eintrag war bereits vorhanden)
											mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], $counter, $spam[$i]['id'], $_POST['message'], $site_name, $type);
											}
										}
									}
								}
							}
						}
					else
						{
						$errorcode = 7; // empty captcha
						}
					}
				elseif ($settings['captcha_method'] == 1)
					{
					if($_POST['captcha'] != "") // captcha is not empty
						{
						$result = mgb_sql_connect("SELECT `sum` FROM ".$db['prefix']."captcha_math LIMIT 1", "Error while checking ifcaptcha is correct.", 1);
						$saved_code = @mysql_fetch_array($result);
						$captcha_code = $saved_code['sum'];
						if($captcha_code != $_POST['captcha']) // captcha is invalid
							{
							$errorcode = 7;  // captcha is not empty, but invalid
							$tracker = 0;
							for ($i = 0; $i < $total; $i++)
								{
								if($_SERVER['REMOTE_ADDR'] == $spam[$i]['ip'] OR $_POST['email'] == $spam[$i]['email'])
									{
									$counter = $spam[$i]['counter'];
									if($counter <= 5)
										{
										$counter = $counter + 1;
										if(mgb_sql_connect("UPDATE `".$db['prefix']."spam` SET `counter` = '".$counter."', `timestamp` = '".time()."' WHERE ID='".$spam[$i]['id']."' LIMIT 1", "Error while saving data into ".$db['prefix']."spam", 0))
											{
											$type = 6; // 6 = Update durch falsch eingegebenes Captcha
											mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], $counter, $spam[$i]['id'], $_POST['message'], $site_name, $type);
											}
										}
									$tracker++;
									}
								}
							if($tracker == 0)
								{
								if(mgb_sql_connect("INSERT INTO ".$db['prefix']."spam (
									name,
									ip,
									email,
									city,
									icq,
									aim,
									msn,
									hp,
									message,
									user_notification,
									user_show_email,
									captcha,
									sent_captcha,
									counter,
									timestamp
									) values (
									'".cleanstr($_POST['name'])."',
									'".cleanstr($_SERVER['REMOTE_ADDR'])."',
									'".cleanstr($_POST['email'])."',
									'".cleanstr($_POST['city'])."',
									'".cleanstr($_POST['icq'])."',
									'".cleanstr($_POST['aim'])."',
									'".cleanstr($_POST['msn'])."',
									'".cleanstr($_POST['hp'])."',
									'".cleanstr($_POST['message'])."',
									'".cleanstr($_POST['user_notification'])."',
									'".cleanstr($_POST['user_show_email'])."',
									'".$captcha_code."',
									'".cleanstr($_POST['captcha'])."',
									'1',
									'".time()."'
									)", "Error while saving data into ".$db['prefix']."spam", 0))
									{
									$type = 5; // 5 = Neueintrag durch falsch eingegebenes Captcha
									mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], "", "", $_POST['message'], $site_name, $type);
									}
								}
							}
						else // captcha is valid
							{
							for ($i = 0; $i < $total; $i++)
								{
								if($_SERVER['REMOTE_ADDR'] == $spam[$i]['ip'] OR $_POST['email'] == $spam[$i]['email'])
									{
									$counter = $spam[$i]['counter'];
									if($counter <= 5)
										{
										$counter = $counter + 1;
										if(mgb_sql_connect("UPDATE `".$db['prefix']."spam` SET `counter` = '".$counter."', `timestamp` = '".time()."' WHERE ID='".$spam[$i]['id']."' LIMIT 1", "Error while saving data into ".$db['prefix']."spam", 0))
											{
											$type = 7; // 7 = Update durch richtig eingegebenes Captcha (Eintrag war bereits vorhanden)
											mgb_spam_mail($charset, $settings['admin_gbemail'], $settings['spam_mail'], $_SERVER['REMOTE_ADDR'], $_POST['name'], $_POST['email'], $_POST['hp'], $_SERVER['HTTP_USER_AGENT'], $counter, $spam[$i]['id'], $_POST['message'], $site_name, $type);
											}
										}
									}
								}
							}
						}
					else
						{
						$errorcode = 7; // empty captcha
						}
					}
				}

			// check email
			if (!check_mail($_POST['email'])) { $errorcode = 4; }

			// check necessary fields
			if (!$_POST['message']) { $errorcode = 1; }
			if (!$_POST['email']) { $errorcode = 2; }
			if (!$_POST['name']) { $errorcode = 3; }
			if ((isset($settings['akismet_plugin'])) AND ($settings['akismet_plugin'] == 1) AND $_POST['user_accept_akismet_service'] != 1) { $errorcode = 11; }

			if (!isset($errorcode) AND $errorcode = 0)
				{
				// delete bbcode
				$_POST['name'] = bbcode_delete($_POST['name']);
				$_POST['message'] = bbcode_delete($_POST['message']);

				$_POST['message'] = nl2br($_POST['message']);
				$t1 = chr(10);
				$t2 = chr(13);
				$_POST['message'] = str_replace($t1,'', $_POST['message']);
				$_POST['message'] = str_replace($t2,'', $_POST['message']);
				
				$name = $_POST['name'];
				$email = $_POST['email'];
				$message = $_POST['message'];
				$url_to_gb = "http://".$settings['h_domain'].$settings['gb_path']."index.php";

				$date = date("d"."/"."m"."/"."Y");
				$time = date("H".":"."i");

				$mail_header = "Content-Type: text/html; charset=".$charset."\r\n";
				$mail_header.= "From: ".$_POST['email']."\r\n";
				$mail_header.= "Reply-To: ".$_POST['email']."\r\n";
				$mail_header.= "X-Mailer: PHP/".phpversion();

				$mail_send = mail($sendemail_email,
					format_mail(repl_uml($lang['email_caption'], $charset), $name, $date, $time, xhtmlbr2nl($message), $settings['h_domain'], $url_to_gb, "", "", "", "", "", ""),
					format_mail(repl_uml($settings['sendmail_contactmail_text'], $charset), $name, $date, $time, xhtmlbr2nl($message), $settings['h_domain'], $url_to_gb, "", "", "", "", "", ""),
					$mail_header);

				if ($mail_send)
					{
					$sendemail_successfull = 1;
					
					if ($_POST['user_sendcopytome'] == 1)
						{
						$mail_send_copy = mail($email,
							format_mail(repl_uml($lang['email_caption'], $charset), $name, $date, $time, xhtmlbr2nl($message), $settings['h_domain'], $url_to_gb, "", "", "", "", "", ""),
							format_mail(repl_uml($settings['sendmail_contactmail_text'], $charset), $name, $date, $time, xhtmlbr2nl($message), $settings['h_domain'], $url_to_gb, "", "", "", "", "", ""),
							$mail_header);

						if (!$mail_send_copy)
							{
							$errorcode = 9;
							}
						}

					// refresh site
					$refresh = "<meta http-equiv=\"refresh\" content=\"3; URL=index.php\">";
					}
				else
					{
					unset($sendemail_successfull);
					$errorcode = 9;
					$refresh = NULL;
					}
				}
			else
				{
				if ($errorcode == 1) { $errormessage = $lang['errormessage1']; } // empty message
				if ($errorcode == 2) { $errormessage = $lang['errormessage2']; } // empty email
				if ($errorcode == 3) { $errormessage = $lang['errormessage3']; } // empty name
				if ($errorcode == 4) { $errormessage = $_POST['email']."&nbsp;".$lang['errormessage4']; } // invalid email
				if ($errorcode == 7) { $errormessage = $lang['errormessage7']; } // invalid captcha
				if ($errorcode == 8) { $errormessage = $lang['errormessage8']; } // user denies emails over guestbook
				if ($errorcode == 11) { $errormessage = $lang['errormessage11']; } // akismet not accepted
				if ($errorcode == 12) { $errormessage = $lang['errormessage12']; } // email blocked by banlist
				if ($errorcode == 13) { $errormessage = $lang['errormessage13']; } // domain blocked by banlist
				if ($errorcode == 14) { $errormessage = $lang['errormessage14']; } // ip blocked by banlist

				// do not refresh site
				$refresh = NULL;

				// generate new captchacode if activated
				if (($settings['captcha'] == 1) AND ($captcha_generated != 1))
					{
					generate_captcha($settings['captcha_method'], $settings['captcha_length'], $settings['captcha_double_hash']);
					$captcha = "<img src=\"includes/captcha.inc.php\" class=\"captcha\" title=\"".$lang['security_code']."\" alt=\"".$lang['security_code']."\">";
					$captcha = template("CAPTCHA_IMG", $captcha, $content_captcha);
					$captcha_generated = 1;
					}
				}
			}
		else
			{
			// user don't wants to receive emails over guestbook
			$errormessage = $lang['errormessage8'];
			$refresh = NULL;
			$sendemail_name = "-";

			// generate new captchacode if activated
			if (($settings['captcha'] == 1) AND ($captcha_generated != 1))
				{
				generate_captcha($settings['captcha_method'], $settings['captcha_length'], $settings['captcha_double_hash']);
				$captcha = "<img src=\"includes/captcha.inc.php\" class=\"captcha\" title=\"".$lang['security_code']."\" alt=\"".$lang['security_code']."\">";
				$captcha = template("CAPTCHA_IMG", $captcha, $content_captcha);
				$captcha_generated = 1;
				}
			}
		}
	else
		{
		// form was not sent
		// do not refresh site
		$refresh = NULL;
		}

	// Generate Page

	// fill header template with content
	$page_header = $content_header;
	
	// check if "install" directory has been deleted
	if (file_exists("install"))
		{
		$page_header = template("INSTALL_DIRECTORY_EXISTS", "<div style=\"background-color: white; padding: 3px; border: 2px solid black; width: 500px;\"><span style=\"color: red; font-size: 12px; font-weight: bold;\">".$lang['install_directory_exists']."</span></div>", $page_header);
		}
	else
		{
		$page_header = template("INSTALL_DIRECTORY_EXISTS", "", $page_header);
		}
		
	$page_header = template("LANGUAGE_SHORT", $language_short, $page_header);
	$page_header = template("DOMAIN", $settings['h_domain'], $page_header);
	$page_header = template("AUTHOR", $settings['h_author'], $page_header);
	$page_header = template("KEYWORDS", $settings['h_keywords'], $page_header);
	$page_header = template("DESCRIPTION", $settings['h_description'], $page_header);
	$page_header = template("CHARSET", $charset, $page_header);
	$page_header = template("REFRESH", $refresh, $page_header);

	if(!isset($errorcode))
		{
		$content_errormessage = NULL;
		}

	// generate captcha image
	if(($settings['captcha'] == 1) AND ($captcha_generated != 1))
		{
		generate_captcha($settings['captcha_method'], $settings['captcha_length'], $settings['captcha_double_hash']);
		$captcha = "<img src=\"includes/captcha.inc.php\" class=\"captcha\" title=\"".$lang['security_code']."\" alt=\"".$lang['security_code']."\">";
		$captcha = template("CAPTCHA_IMG", $captcha, $content_captcha);
		$captcha_generated = 1;
		}

		// insert template if akismet is acitvated
		if (file_exists("plugins/akismet/akismet.class.php") AND (isset($settings['akismet_plugin'])) AND ($settings['akismet_plugin'] == 1))
			{
			$content_email_user_accept_akismet_service = template("LANG_USER_ACCEPT_AKISMET_SERVICE", $lang['user_accept_akismet_service'], $content_email_user_accept_akismet_service);
			$user_accept_akismet_service = $content_email_user_accept_akismet_service;
			}
		else
			{
			$user_accept_akismet_service = NULL;
			}

	 // entry was not successfull or it is the first time the site is loaded
	if(!isset($sendemail_successfull))
		{
		// get data from template
		$page_email_body = $content_email_body;

		// eMail could not be sent, show errormessage
		if(isset($errorcode) AND $errorcode == 9) { $errormessage = $lang['errormessage9']; }

		// generate captchacode if activated
		if (($settings['captcha'] == 1) AND ($captcha_generated != 1))
			{
			generate_captcha($settings['captcha_method'], $settings['captcha_length'], $settings['captcha_double_hash']);
			$captcha = "<img src=\"includes/captcha.inc.php\" class=\"captcha\" title=\"".$lang['security_code']."\" alt=\"".$lang['security_code']."\">";
			$captcha = template("CAPTCHA_IMG", $captcha, $content_captcha);
			$captcha_generated = 1;
			}

		// fill template with other templates if set
		$page_email_body = template("HEADER", $page_header, $page_email_body);
		$page_email_body = template("TEMPLATE_ERRORMESSAGE", $content_errormessage, $page_email_body);
		$page_email_body = template("TEMPLATE_CAPTCHA", $captcha, $page_email_body);
		$page_email_body = template("TEMPLATE_COPYRIGHT", $content_copyright, $page_email_body);
		$page_email_body = template("TEMPLATE_FOOTER", $content_footer, $page_email_body);
		$page_email_body = template("MGB_VERSION", $settings['version'], $page_email_body);
		$page_email_body = template("COPYRIGHT_DATE", date("Y"), $page_email_body);
		$page_email_body = template("ICONSET_PATH", $settings['iconset_path'], $page_email_body);
		$page_email_body = template("TEMPLATE_PATH", "templates/".$settings['template_path'], $page_email_body);
		$page_email_body = template("TEMPLATE_STYLE_PATH", $settings['template_style_path'], $page_email_body);
		$page_email_body = template("TEMPLATE_USER_ACCEPT_AKISMET_SERVICE", $user_accept_akismet_service, $page_email_body);

		// fill template with language and text strings
		if(!isset($errormessage)) { $errormessage = NULL; }
		$page_email_body = template("ERRORMESSAGE", $errormessage, $page_email_body);
		$page_email_body = template("TITLE", $settings['title'], $page_email_body);
		$page_email_body = template("EMAIL_RECEIVER", $sendemail_name, $page_email_body);

		// fill template with sent strings
		if(!isset($_POST['sent']))
			{
			$_POST['name'] = "";
			$_POST['email'] = "";
			$_POST['message'] = "";
			}

		$page_email_body = template("POST_NAME", $_POST['name'], $page_email_body);
		$page_email_body = template("POST_EMAIL", $_POST['email'], $page_email_body);
		$page_email_body = template("POST_MESSAGE", $_POST['message'], $page_email_body);

		// fill template with general data
		$page_email_body = template("FORM_ACTION", "email.php?id=".cleanstr($_GET['id']), $page_email_body);

		$page_email_body = mgb_template_language($page_email_body, "language/".$settings['language_path']."/lang_main.php", $settings['debug_mode']); // last number defines debug mode
		}
	else
		{
		 // entry was successfull, load other template
		$page_email_body = $content_email_body_success;

		// fill template with other templates and load them first
		$page_email_body = template("HEADER", $page_header, $page_email_body);
		$page_email_body = template("TEMPLATE_PATH", "templates/".$settings['template_path'], $page_email_body);
		$page_email_body = template("TEMPLATE_STYLE_PATH", $settings['template_style_path'], $page_email_body);
		$page_email_body = template("TEMPLATE_COPYRIGHT", $content_copyright, $page_email_body);
		$page_email_body = template("TEMPLATE_FOOTER", $content_footer, $page_email_body);

		// then strings
		$page_email_body = template("TITLE", $settings['title'], $page_email_body);
		$page_email_body = template("MGB_VERSION", $settings['version'], $page_email_body);
		$page_email_body = template("COPYRIGHT_DATE", date("Y"), $page_email_body);
		$page_email_body = template("ICONSET_PATH", $settings['iconset_path'], $page_email_body);

		$page_email_body = mgb_template_language($page_email_body, "language/".$settings['language_path']."/lang_main.php", $settings['debug_mode']); // last number defines debug mode
		}

	echo $page_email_body;
?>
Return current item: MGB OpenSource Guestbook