<?php require_once 'protect.php'; ?>
<?php if ($sitemail) { ?>
<?php
if (isset($_POST['submitf'])) {
$namef = $mysqli->real_escape_string(strip_tags($_REQUEST['namef']));
$namef = mb_convert_case($namef, MB_CASE_TITLE, "UTF-8");
$emailf = $mysqli->real_escape_string(strip_tags($_REQUEST['emailf']));
$emailf = strtolower($emailf);
$subjectf = $mysqli->real_escape_string(strip_tags($_REQUEST['subjectf']));
$commentsf = $mysqli->real_escape_string(strip_tags($_REQUEST['commentsf']));
$commentsf = str_replace('\r\n', ' ',$commentsf);
$commentsf = preg_replace('/\s+/', ' ',$commentsf);

if ($_REQUEST['notesf']=='' AND $namef!=' ' AND $namef!='' AND strpos($commentsf, 'http') === false AND (filter_var($emailf, FILTER_VALIDATE_EMAIL)) AND $_REQUEST['dataf']==$_POST['codef']) {

$mysqli->query("INSERT INTO requests (name, tel, email, items, comments, url) VALUES ('$namef', '$telephonef', '$emailf', '$subjectf', '$commentsf', '$pagepath')");

$subject="Message $domain";

$to="$sitemail";
$from="$emailf";
$reply="$emailf";
$headers="MIME-Version: 1.0\r\n";
$headers .="Content-type: text/plain; charset=utf-8\r\n";
$headers .="Bcc: $bcc\r\nFrom: $from\r\nReply-To: $reply";
$subject="Message $domain";

$message="$subject
______________________________________________________________________________________

$fieldname: $namef
Email: $emailf
$fieldsubject: $subjectf
$fieldcomments: $commentsf
______________________________________________________________________________________

www.$domain
";
mail ($to, $subject, $message, $headers);
}?>
<div><?php echo $fieldtext1 ?></div>

<?php } else { ?> 
<div>
<form name="formad" method="post">

<div><label for="namef" class="hlabel"><?php echo $fieldname ?></label>
<input type="text" name="namef" id="namef" placeholder="<?php echo $fieldname ?>*" size="19" maxlength="50" class="formsd forms1" required>
<label for="emailf" class="hlabel">Email</label>
<input type="email" name="emailf" id="emailf" placeholder="Email*" size="19" maxlength="60" class="formsd forms1" required></div>
<div><label for="subjectf" class="hlabel"><?php echo $fieldsubject ?></label>
<input type="text" name="subjectf" id="subjectf" placeholder="<?php echo $fieldsubject?>" size="30" maxlength="60" class="formsd"></div>
<div><label for="commentsf" class="hlabel"><?php echo $fieldmessage ?></label>
<textarea name="commentsf" id="commentsf" placeholder="<?php echo $fieldmessage?>*" rows="5" cols="30" class="formsd" required></textarea></div>
<label class="hlabel">note<input type="text" name="notesf" id="notesf" size="1" maxlength="20" class="formsn"></label>

<div class="divsubmit">
<?
global $dataf;
$dataf = mt_rand(100000,1000000);
?>
<label for="codef" class="hlabel"><?php echo $fieldcode ?></label>
<input type="hidden" name="codef" value="<?php echo $codef ?>">
<input type="hidden" name="dataf" value="<?php echo $dataf ?>"> 
<img src="<?php echo $codepath ?>includes/dynamicimage.php?dt=<? global $dataf; echo base64_encode($dataf);?>" alt="">
<input type="text" name="codef" id="codef" placeholder="<?php echo $fieldcode ?>" size="16" maxlength="6" class="inputcode" required>

<input type="submit" name="submitf" class="button buttond" value="<?php echo $button1 ?>">
</div>
</form>
</div>
<?php } ?>
<?php } ?>