Im doing a job for web development company that is serving as a "test" of my skills, its pretty basic, simply an HTML form that does the following:
Sends an Email to a specified Email Addy
Stores the Email in a database with the date it was submitted
Has a simple backend to choose date ranges and create XLS spreadsheets from that.
Before I submit the code to them, I just want your opinions on my coding, whether I have missed anything, need to add anything, etc. Pretty much, rip my code apart and tell me what you think...
EDIT**** Heres the pastebin URLs for the code - Easier to see there...
Frontend: PHP pastebin - collaborative debugging tool
Backend: PHP pastebin - collaborative debugging tool
Front End:
Sends an Email to a specified Email Addy
Stores the Email in a database with the date it was submitted
Has a simple backend to choose date ranges and create XLS spreadsheets from that.
Before I submit the code to them, I just want your opinions on my coding, whether I have missed anything, need to add anything, etc. Pretty much, rip my code apart and tell me what you think...
EDIT**** Heres the pastebin URLs for the code - Easier to see there...
Frontend: PHP pastebin - collaborative debugging tool
Backend: PHP pastebin - collaborative debugging tool
Front End:
Code:
<?php
// Config File
require_once("Admin/config.php");
// If form has been submitted
if($_POST['submitform']) {
mysql_connect($sqlServer, $sqlUsername, $sqlPassword);
@mysql_select_db($sqlDatabase) or die("Cannot Select Database");
// Addslashses Function
function myAddSlashes( $string ) {
if (get_magic_quotes_gpc()) {
return ( $string );
} else {
return ( addslashes ( $string ) );
}
}
foreach($_POST as $formInput) {
myAddSlashes($formInput);
}
// POST VARS
$Subject = $_POST['Subject'];
$Name = $_POST['Name'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Message = $_POST['messageText'];
// Check to see if all forms are filled in
$requiredVars = $_POST['requiredVars'];
$requiredExplode = explode(",", $requiredVars);
$requiredExplode = explode(",",$requiredVars);
while(list($requiredCheck) = each($requiredExplode)) {
if(!$$requiredExplode[$requiredCheck]) {
die($requiredExplode[$requiredCheck]." is empty. Please go back and fill it in.");
}
}
// Todays Date for Submission
$todaysDate = date('Y-m-d');
// Error Check Email Address Format
if(!preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $Email)) {
echo "Email address does not appear to be in the correct format";
} else { // If its good, continue
// MySQL Query
$query = "INSERT INTO `emails` (Id, Subject, Name, Phone, Email, Message, Date) VALUES (NULL, '$Subject, '$Name', '$Phone', '$Email', '$Message', '$todaysDate')";
mysql_query($query);
// If Query was Successful show thank you message, else, display error
if(mysql_affected_rows() > 0) {
$emailSubject = $Subject;
$emailMessage = $Message;
$emailHeaders = 'From: test@lazydcreations.com' . "\r\n" .
'Reply-To: test@lazydcreations.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
//mail($recipEmail, $emailSubject, $emailMessage, $emailHeaders);
// Thank you message
echo $thankYou;
} else {
//echo "There was a problem with your form submission";
echo "There was a problem with your form submission. Please go back and check that all fields are filled in correctly";
}
}
} else { // If form hasnt been submitted
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>Contact Form - LazyD</title>
</head>
<body>
<form action="#" method="post">
<input type="hidden" name="requiredVars" value="Subject,Name,Email,Phone,Message">
<table width="370" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="113"><div class="formText">Subject:</div></td>
<td width="257"><input name="Subject" type="text" size="36" class="customTextField" /></td>
</tr>
<tr>
<td height="6" colspan="2"></td>
</tr>
<tr>
<td><div class="formText">Name:</div></td>
<td><input name="Name" type="text" size="36" id="Name" class="customTextField" /></td>
</tr>
<tr>
<td height="6" colspan="2"></td>
</tr>
<tr>
<td><div class="formText">Phone:</div></td>
<td width="257">
<input name="Phone" type="text" size="36" id="Phone" class="customTextField" /> </td>
</tr>
<tr>
<td height="6" colspan="2"></td>
</tr>
<tr>
<td><div class="formText">Email Address: </div></td>
<td><input name="Email" type="text" size="36" id="Email" class="customTextField" /></td>
</tr>
<tr>
<td height="31" colspan="2"></td>
</tr>
<tr>
<td><div class="formText" style="text-align:left;">Message:</div></td>
</tr>
<tr>
<td colspan="6"><textarea name="messageText" id="messageText" cols="68" rows="10"></textarea></td>
</tr>
<tr>
<td height="16" colspan="2"></td>
</tr>
<tr>
<td colspan="2"><input name="submitform" type="submit" id="Submit" value="Submit Form" class="customButtonFormat" /></td>
</tr>
</table>
</form>
</body>
</html>
<?php } ?>