<!DOCTYPE HTML>  
<html>
<head>
<meta charset="UTF-8">
<title>ANSAFS</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="icon" href="images/logo7.png" type="image/png" sizes="16x16">
<link href="css/ansa1.css" rel="stylesheet">
</head>
<body>
<header role="banner">
  <h1>ANSA Financial Solutions Inc.<img src="images/logo7.png" align="left"  width="100" height="60"></h1>
  <nav role="navigation">
    <ul>
      	<li><a href="index.html" title="Home" >Home</a></li>
	<li><a href="bookinfo.html" title="Book Information">Book Information</a></li>
	<li><a href="PlanningResources.html" title="Planning Resources">Planning Resources</a></li>
      	<li><a href="usefulresources.html" title="Useful Resources">Useful Resources</a></li>
	<li><a href="ansacontact.php" title="Contact"  class="current">Contact</a></li>
     </ul>
  </nav>
</header>
<main role="main"> <h3 align ="Left">Contact</h3>

<h5>Information Request form:</h5>
<p> <b> To order books or for any comments/questions, please fill the form below and make sure to click <b><u>submit</u></b>.</b></p>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
<p>Name:&emsp;&ensp;&nbsp;       <input type="text" name="name" value="<?php echo $name;?>">
  <span class="error">* <?php echo $nameErr;?></span></p>

<p>E-mail:&emsp;&ensp;     <input type="text" name="email" value="<?php echo $email;?>">
	<span class="error">* <?php echo $emailErr;?></span></p>
<p>Telephone:  <input type="text" name="tel" value="<?php echo $tel;?>"> </p>
<p>Comment: (if ordering Books, please state the number of books) <br>   
	<textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
  </p>
  <input type="submit" name="submit" value="Submit">  
</form>
<p> <b> Your Message will be mailed to Kam Chari</b></p>
<h2 align ="center">   </h2>
<footer role="contentinfo">
   <section class="links">
	<div class="item">
        <h5>Contact</h5>
        <p> Kam Chari, MBA, CPA, CFP, RFP, CHFC<br>ANSA Finacial Solutions <br>Ph: <a href="tel:4168318899">(416) 831-8899</a><br> Email:<a href="mailto:kam@ansafinancialsolutions.com" target="_top">kam@ansafinancialsolutions.com</a></p>
     </div>

    </section>
  <h5 align ="center">© 2020 Copyright ANSA Financial Solutions Inc. All rights reserved.</h5>
</footer>
</main>
</body>
<body>  

<?php
// define variables and set to empty values
$nameErr = $emailErr = "";
$name = $email = $comment = $subject = $recipient = $mailbody ="";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["name"])) {
    $nameErr = "Name is required";
  } else {
    $name = test_input($_POST["name"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
      $nameErr = "Only letters and white space allowed";
    }
  }
  
  if (empty($_POST["email"])) {
    $emailErr = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
    }
  }
    
  if (empty($_POST["tel"])) {
    $tel = "";
  } else {
    $tel = test_input($_POST["tel"]);
  }

  if (empty($_POST["comment"])) {
    $comment = "";
  } else {
    $comment = test_input($_POST["comment"]);
  }

}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>


<?php

$recipient="nkc.chari@gmail.com";

$subject="Information Request";

$mailbody="Name: $name\nEmail: $email\nTelephone Number: $tel\n\nComment: $comment";

mail ($recipient, $subject,  $mailbody, "From: $name <$email>");


?>

</body>
</html>
