<?php
if (isset($_POST["email"])) {
$ToEmail = 'jenarhanes@gmail.com';
$EmailSubject = 'Jena web design contact form submitted';
$mailheader = "From:".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."\r\n";
$MESSAGE_BODY .= "Budget: ".$_POST["budget"]."\r\n";
$MESSAGE_BODY .= "Timeline: ".$_POST["timeline"]."\r\n";
$MESSAGE_BODY .= "Project: ".$_POST["project"]."\r\n";
$MESSAGE_BODY .= "Message: ".$_POST["message"]."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Your message was sent!
<?php
} else {
$nameErr = $emailErr = $budgetErr = $timelineErr = $projectErr = $messageErr ="";
$name = $email = $budget = $timeline = $project = $message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required.";
} else {
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z]*$/",$name)) {
$nameErr = "Please only use letters and white space.";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required.";
} else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Please enter a valid email.";
}
}
if (empty($_POST["budget"])) {
$budgetErr = "Please provide at least an estimate of your budget.";
} else {
$budget = test_input($_POST["budget"]);
}
if (empty($_POST["timeline"])) {
$timelineErr = "I'll need to have an idea of how much time there is to complete the project.";
} else {
$timeline = test_input($_POST["timeline"]);
}
if (empty($_POST["project"])) {
$projectErr = "Please let me know if this is a design project, a development project, or both.";
} else {
$project = test_input($_POST["project"]);
}
if (empty($_POST["message"])) {
$messageErr = "Please input your message.";
} else {
$message = test_input($_POST["message"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
};
?>
<h1>Hire Me!</h1>
<p>I'm currently accepting new projects.<br />
Please fill out the form below or simply email me at <a href="mailto:jenarhanes@gmail.com">jenarhanes@gmail.com</a>.</p>
<p>All fields are required.</p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<p>Your Full Name:<br />
<input type="text" name="name" />
<span class="error">* <?php echo $nameErr; ?></span><br />
Email:<br />
<input type="text" name="email" />
<span class="error">* <?php echo $emailErr; ?></span><br />
Budget:<br />
<input type="text" name="budget" />
<span class="error">*<?php echo $budgetErr; ?></span><br />
Timeline:<br />
<input type="text" name="timeline" />
<span class="error">*<?php echo $timelineErr; ?></span><br />
Project Type:<br />
<input type="text" name="project" />
<span class="error">*<?php echo $projectErr; ?></span><br />
Please give me some details about your project:<br />
<textarea name="message" rows="5" cols="40"></textarea>
<span class="error">* <?php echo $messageErr; ?></span><br />
<input type="submit" />
</p>
</form>