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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</td>
				<td>
					<input id="pages1" type="radio" name="pages" dojoType="dijit.form.RadioButton" />
					<label for="pages1">1-5</label>
					&nbsp;
					<input id="pages2" type="radio" name="pages" dojoType="dijit.form.RadioButton" />
					<label for="pages2">6-20</label>
					&nbsp;
					<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>&nbsp;</td>
				<td>
					<p>
					<input id="Web Design" type="checkBox" name="services" dojoType="dijit.form.CheckBox" />
					<label for="Web Design">Web Design</label>
					&nbsp;
					<input id="Programming" type="checkBox" name="services" dojoType="dijit.form.CheckBox" />
					<label for="Programming">Programming</label>
					&nbsp;
					<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>&nbsp;</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>

    I've had a quick look. Could it be something to do with

    elseif(!$name)
    {
    $errorMsg = "Please enter a name";

    }

    I think with this code you'll always get an error message. Do you get one?

      The thing is the code won't even get to my javascript alert statement. So I don't know if it is that, but at one point the code was working and the name part is what it was when the code was working.

        I think you need to work this out first. I usually add:

        echo 'error here';
        exit();

        to each part of my code and test it. It's unsophisticated but works on relatively short pieces of code.

          How is that any different from what I am doing with the javascript?

            You're using an image called 'submit' as the form's input. You're then checking for $POST['submit'] in your script - image submits turn into name_x and name_y, so look for isset($POST['submit_x']) instead.

              Drakla;10878017 wrote:

              You're using an image called 'submit' as the form's input. You're then checking for $POST['submit'] in your script - image submits turn into name_x and name_y, so look for isset($POST['submit_x']) instead.

              almost! IE does as you say above, Firefox et al passes both

                dagon;10878022 wrote:

                almost! IE does as you say above, Firefox et al passes both

                Not the version of Firefox I just tested it with. You get your x and y and that's it.

                  Write a Reply...