Hello, I have some code that is not working, I want the page to send an email when the user hits the submit button, here is my code:
<?php
$errorMsg = "";
if(isset($_POST['submit']))
{
echo "<script type='text/javascript'>alert('now here');</script>";
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$phone = $_POST['phone'];
$pages = $_POST['pages'];
$services = $_POST['services'];
// Run tests on email address
function isValidEmailAddress($email)
{
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c[\\x00-\\x7f]';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}
// First check and see if they entered a valid email
if(!isValidEmailAddress($email))
{
$errorMsg = "Please enter a valid email";
}
// Then make sure they entered a name
elseif(!$name)
{
$errorMsg = "Please enter a name";
}
$myServices = "";
foreach ($services as $val)
{
$myServices .= $val.", ";
}
// If everything is valid, send the email
if($errorMsg == "")
{
echo "<script type='text/javascript'>alert('we are here');</script>";
if(get_magic_quotes_gpc())
{
$name = stripslashes($name);
$email = stripslashes($email);
$phone = stripslashes($phone);
$comments = stripslashes($comments);
}
// Send Email
$to = "ihavemyemailhere";
$subject = "Customer Inquiry";
$body = "Hello my name is $name \n" .
"My email is $email \n" .
"My phone number is $phone \n" .
"I want $pages \n" .
"I need these services: $myServices \n" .
$comments;
mail($to, $subject, $body);
?>
<div id="mainBody"><p>Your message has been sent. I will contact you shortly.</p></div>
<?php
}
}
if(!isset($_POST['submit']) || $errorMsg != '')
{
?>
<div id="mainBody" style="width: 35%; height: 400px;">
<h2>Fill out the from below to receive a free quote!</h2>
<?=$errorMsg;?>
<form method="post" action="contact.php" name="mailForm" id="mailForm">
<table>
<tr>
<td>*Name:</td>
<td> </td>
<td><input id="name" type="text" name="name" value="<?=$name;?>" columns="15" dojoType="dijit.form.TextBox"
maxLength="35" onfocus="dojox.fx.highlight({node:'name', color:'#0066FF', duration:800}).play()" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>*Email:</td>
<td> </td>
<td><input id="email" type="text" name="email" value="<?=$email;?>" dojoType="dijit.form.TextBox"
maxLength="35" onfocus="dojox.fx.highlight({node:'email', color:'#0066FF', duration:800}).play()" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Phone Number</td>
<td> </td>
<td><input id="phone" type="text" name="phone" value="<?=$phone;?>" dojoType="dijit.form.TextBox"
maxLength="10" onfocus="dojox.fx.highlight({node:'phone', color:'#0066FF', duration:800}).play()" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Pages:</td>
<td> </td>
<td>
<input id="pages1" type="radio" name="pages" dojoType="dijit.form.RadioButton" />
<label for="pages1">1-5</label>
<input id="pages2" type="radio" name="pages" dojoType="dijit.form.RadioButton" />
<label for="pages2">6-20</label>
<input id="pages3" type="radio" name="pages" dojoType="dijit.form.RadioButton" />
<label for="pages3">20+</label>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Services</td>
<td> </td>
<td>
<p>
<input id="Web Design" type="checkBox" name="services" dojoType="dijit.form.CheckBox" />
<label for="Web Design">Web Design</label>
<input id="Programming" type="checkBox" name="services" dojoType="dijit.form.CheckBox" />
<label for="Programming">Programming</label>
<input id="DBA" type="checkBox" name="services" dojoType="dijit.form.CheckBox" />
<label for="DBA">DBA</label>
</p>
<p>
<input id="Domain Name Registration" type="checkBox" name="services[]" dojoType="dijit.form.CheckBox" />
<label for="Domain Name Registration">Domain Name Registration</label>
</p>
</td>
</tr>
<tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<td>Comments:</td>
<td> </td>
<td><input id="comments" type="text" name="comments" dojoType="dijit.form.SimpleTextarea" rows="5"
columns="15" onfocus="dojox.fx.highlight({node:'comments', color:'#0066FF', duration:800}).play()" /></td>
</tr>
</table>
<br />
<input type="image" src="images/Submit_Button.png" name="submit" id="submit" onclick="return checkForm();" />
<br />
<p>
* Denotes required field
</p>
</form>
</div>
<?php
}
?>
<div id="rightNav" style="margin: 3% 0 0 5%;">
<p>
<? include 'rightNav.inc'; ?>
</p>
</div>
<div id="footer">
<? include 'footer.inc'; ?>
</div>
</body>
</html>