SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without source code there is no way we can help you.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <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>
    Code:
    <?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:\n Name of Parent: $p_fname $p_lname \n Email of Parent: $p_email \n Name of Student: $s_fname  $s_lname \n Email of Student: $s_email \n Year: $year \n 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>

  4. #4
    SitePoint Member
    Join Date
    Feb 2011
    Location
    Boston, MA
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your web host's SMTP server maybe delaying your messages. Have you discussed this issue with them?

  5. #5
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  6. #6
    SitePoint Member
    Join Date
    Mar 2011
    Location
    Tyne & Wear
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using PEAR's mail classes, I find them much more stable than using pure sendmail.

    Mail

  7. #7
    SitePoint Addict
    Join Date
    Aug 2010
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay I stuck to the orignal form I downloaded, and this is what I have now. I think everything is stable now.

    Code:
    <?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 .= "\n 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 .= "\n 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:\n Name of Parent: $p_fname $p_lname \n Email of Parent: $p_email \n Name of Student: $s_fname  $s_lname \n Email of Student: $s_email \n Year: $year \n 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>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •