Trouble with contact form

Register - Face to Face Tutoring

Whenever I test this form out, sometimes it will come to my email instantly, sometimes it can take 15min and other times it just doesn’t come at all.

I feel if I test them consecutively they sent out right away. But if I do a test randomly, I need to do one or two before I receive one.

This is obviously cannot happen.

I’m new to contacts forms and using php, so maybe I’m missing something?

Without source code there is no way we can help you.

<div id="content">
	
		<form id="register" method="post" name="contactform" action="contact-form-handler.php">
		<fieldset>
		<legend>Face to Face Tutoring Registration</legend>
		
		<br/>
		<label for="p_fname" class="fixed">First & Last Name (Parent):<span class="red">*</span></label>
		<input class="n_text" type="text" name="p_fname" id="p_fname" />
		<input class="n_text" type="text" name="p_lname" id="p_lname" />
		
		<br/><br/>
		
		
		<label for="s_fname" class="fixed">First & Last Name (Student):<span class="red">*</span></label>
		<input class="n_text" type="text" name="s_fname" id="s_fname"/>
		<input class="n_text" type="text" name="s_lname" id="s_lname"/>
		
		<br/><br/>
		
		
		<label for="p_email" class="fixed">Email (Parent):<span class="red">*</span></label>
		<input class="text" type="text" name="p_email" id="p_email" />
		
		<br/><br/>

	
		<label for="s_email" class="fixed">Email (Student):<span class="red">*</span></label>
		<input class="text" type="text" name="s_email" id="s_email" />

		<br/><br/>
		
		<label for="subject" class="fixed">Subject(s) student<br/> needs help in:<span class="red">*</span></label>
		<textarea class="subject_text" cols="25" rows="5" id="subject" name="subject"></textarea>
	

		<br/><br/>
		
		
		<div id="years">
			<p class="year">Year of Student:<span class="red">*</span></p>
			
			<label for="Freshmen" class="btnRadio">Freshmen</label>
			<input type="radio" name="year" id="Freshmen"  value="Freshmen"/>

			<label for="Sophomore" class="btnRadio" >Sophomore</label>
			<input type="radio" name="year" id="Sophomore" value="Sophomore"/>

			<label for="Junior" class="btnRadio">Junior</label>			
			<input type="radio" name="year" id="Junior" value="Junior"/>

			<label for="Senior" class="btnRadio">Senior  </label>	
			<input type="radio" name="year" id="Senior" value="Senior"/>
	
		</div><!-- End years -->
		
		<div class="buttonarea"><input type="submit" name="Register" value="Submit"/></div>
		
		</fieldset>
		</form>

<?php 

$errors = '';
$myemail = 'baderup99@aol.com';//<-----Put Your email address here.


$p_fname = $_POST['p_fname'];
$p_lname = $_POST['p_lname'];
$s_fname = $_POST['s_fname'];
$s_lname = $_POST['s_lname'];
$p_email = $_POST['p_email'];
$s_email = $_POST['s_email'];
$year = $_POST['year'];
$subject = $_POST['subject'];

if( empty($errors))
{
	$to = $myemail; 
	$email_subject = "Registration submission from FacetoFaceTutoring: $name";
	$email_body = "You have received a new registration. ".
	" Here are the details:\
 Name of Parent: $p_fname $p_lname \
 Email of Parent: $p_email \
 Name of Student: $s_fname  $s_lname \
 Email of Student: $s_email \
 Year: $year \
 Subject: $subject"; 
	
	$headers = "From: $myemail"; 
	$headers .= "Reply-To: $p_email";
	
	mail($to,$email_subject,$email_body,$headers);
	//redirect to the 'thank you' page
	header('Location: contact-form-thank-you.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

Your web host’s SMTP server maybe delaying your messages. Have you discussed this issue with them?

You’re also not testing your mail() function inside an if conditional like this:

if(mail())

Thats the only way you can tell if mail() actually worked or not.

Try using PEAR’s mail classes, I find them much more stable than using pure sendmail.

Mail

Okay I stuck to the orignal form I downloaded, and this is what I have now. I think everything is stable now.

<?php 

$errors = '';
$myemail = 'baderup99@aol.com';//<-----Put Your email address here.
if(empty($_POST['p_fname'])  ||
	empty($_POST['p_lname'])  || 
	empty($_POST['s_fname'])  || 
	empty($_POST['s_lname'])  || 
	empty($_POST['p_email'])  ||  
    empty($_POST['s_email']) ||
    empty($_POST['year'])  ||  
    empty($_POST['subject']))
{
    $errors .= "\
 Error: all fields are required";
}

$p_fname = $_POST['p_fname'];
$p_lname = $_POST['p_lname'];
$s_fname = $_POST['s_fname'];
$s_lname = $_POST['s_lname'];
$p_email = $_POST['p_email'];
$s_email = $_POST['s_email'];
$year = $_POST['year'];
$subject = $_POST['subject'];

if (!eregi(
"^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$", 
$p_email))
{
    $errors .= "\
 Error: Invalid email address";
}

if( empty($errors))
{
	$to = $myemail; 
	$email_subject = "Registration submission from FacetoFaceTutoring: $name";
	$email_body = "You have received a new registration. ".
	" Here are the details:\
 Name of Parent: $p_fname $p_lname \
 Email of Parent: $p_email \
 Name of Student: $s_fname  $s_lname \
 Email of Student: $s_email \
 Year: $year \
 Subject: $subject"; 
	
	$headers = "From: $myemail"; 
	$headers .= "Reply-To: $p_email";
	
	mail($to,$email_subject,$email_body,$headers);
	//redirect to the 'thank you' page
	header('Location: contact-form-thank-you.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>&#63232;
</html>