<?php require_once 'protect.php'; ?>
<?php
if (isset($_POST['submit'])) {
$name = $mysqli->real_escape_string(strip_tags($_REQUEST['name']));
$name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8");
$name = preg_replace('/\s+/', ' ',$name);
$toname = $mysqli->real_escape_string(strip_tags($_REQUEST['toname']));
$email = $mysqli->real_escape_string(strip_tags($_REQUEST['email']));
$email = strtolower($email);
$email = preg_replace('/\s+/', '',$email);
$toemail = $mysqli->real_escape_string(strip_tags($_REQUEST['toemail']));
$comments = $mysqli->real_escape_string(strip_tags($_REQUEST['comments']));
$comments = str_replace('\r\n', ' ',$comments);
$comments = preg_replace('/\s+/', ' ',$comments);
$rbphoto = $mysqli->real_escape_string(strip_tags($_REQUEST['rbphoto']));
		
if ($_REQUEST['notes']=='' AND $name!=' ' AND $name!='' AND (filter_var($email, FILTER_VALIDATE_EMAIL)) AND $_REQUEST['data']==$_POST['code1']) {

$to="$tomail";
$from="$email";
$reply="$email";
$headers="MIME-Version: 1.0\r\n";
$headers .="Content-type: text/plain; charset=utf-8\r\n";
$headers .= "From: $email<$email>\r\n";
$subject="E-card $domain";
$message='
			
<html>
<head>
<title>E-card</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#444444" leftmargin="0" topmargin="0" link="#996699" vlink="#996699" alink="#996699">
<div style="text-align: center;"> 
<font size="4" color="#666666">Dear '.$toname.', greetings from '.$sitecompany.' <br> '.$name.' </font>
</div>
<div style="text-align: center;"> 
'.$comments.'
<hr>
</div>
<div style="text-align: center; padding: 10px; background: #cccccc;"><img src="'.$protocol.'www.'.$domain.'/files/photos/'.$rbphoto.'.jpg"></div>
</body>
</html>
';
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: ".$name."<".$email.">\r\n";
$to  = $toemail ;
mail ($to, $subject, $message, $headers);
?>

<?php echo $fieldtext1 ?>
 
<hr>
 
<div>
<?php echo $textfrom ?>: <?php echo $name ?> - <?php echo $email ?><br>
<?php echo $textto ?>: <?php echo $toname ?> - <?php echo $toemail ?><br>
<?php echo $fieldcomments ?>: <?php echo $comments ?>
</div>
 
<?php } else { ?>

<a href="javascript:history.go(-1);"><?php echo $fieldtext2 ?></a> 

<?php } ?>
<?php } else { ?>  

<form name="forma" method="post">	
<div class="margtop20">
<?php
$result20 = $mysqli->query("SELECT * FROM extras WHERE type=0 GROUP BY insert_id ORDER BY category_id desc, item_id, priority LIMIT 8");
while($row = $result20->fetch_array()) {
$count++;
$photoid=$row['insert_id'];
$photo=$row['name'];
$ppriority=$row['priority'];

if ($photo=='') { 
$photo=$sitecompany;
}
?>
<div class="floatleft marg5">
<a id="thumb<?php echo $photoid ?>" href="<?php echo $filepath ?>photos/<?php echo $photoid ?>.jpg" onclick="return hs.expand(this)">
<img src="<?php echo $codepath ?>includes/image.php?image=<?php echo $imagepath ?>photos/<?php echo $photoid ?>.jpg&amp;nwidth=100" alt="<?php echo $photo ?> <?php echo $phcount ?>" title="<?php echo $photo ?>" class="pphoto"></a>
<div class="text-center"><input name="rbphoto" type="radio" value="<?php echo $photoid ?>"<?php if ($count==1) { echo " checked"; }?>></div>
</div>
<?php } ?> 
</div>
  
<hr>

<div class="divfloat1 margbottom20">
<div class="titles"><?php echo $textfrom ?></div>
<hr>
<div><label for="name" class="hlabel"><?php echo $fieldname ?></label> <input type="text" name="name" id="name" placeholder="<?php echo $fieldname ?>" size="20" maxlength="50"></div>
<div><label for="email" class="hlabel">Email</label> <input type="email" name="email" id="email" placeholder="Email" size="20" maxlength="60"></div>
<div><label for="comments" class="hlabel"><?php echo $fieldcomments ?></label> <textarea name="comments" id="comments" placeholder="<?php echo $fieldcomments ?>" rows="4" cols="30"></textarea></div>
</div>

<div class="divfloat2">
<div class="titles"><?php echo $textto ?></div>
<hr>
<div><label for="toname" class="hlabel"><?php echo $fieldname ?></label> <input type="text" name="toname" id="toname" placeholder="<?php echo $fieldname ?>" size="20" maxlength="50"></div>
<div><label for="toemail" class="hlabel">Email*</label> <input type="email" name="toemail" id="toemail" placeholder="Email*" size="20" maxlength="60" required></div>
<div>
<label for="code1" class="hlabel"><?php echo $fieldcode ?></label>
<?
global $data;
$data = mt_rand(100000,1000000);
?>
<input type="hidden" name="code1" value="<?php echo $code1 ?>">
<input type="hidden" name="data" value="<?php echo $data ?>"> 
<img src="<?php echo $codepath ?>includes/dynamicimage.php?dt=<? global $data; echo base64_encode($data);?>" alt="">
<input type="text" name="code1" id="code1" placeholder="<?php echo $fieldcode ?>" size="16" maxlength="6" class="inputcode" required>
<label class="hide">note<input type="text" name="notes" id="notes" size="1" maxlength="20" class="formsn"></label>
</div>

<div class="divsubmit"><input type="submit" name="submit" class="button buttonsubmit" value="<?php echo $button1 ?>"></div>
<div class="divrequired color2">* <?php echo $fieldrequired ?></div>
</div>
</form>
<?php } ?>
<div class="cleared"></div>