Basic Contact Form Problem

Discussion in 'PHP' started by Adnan959, Mar 10, 2011.

  1. #1
    Hey Guys,

    I have some code written for a contact form which incorporates a CAPTCHA. It sends out an email to the assigned email address with the query.

    I want to keep the above mentioned functionality and also make it so the script sends out an automated response to the person who contacted us. Something in the lines of a "thank you" message.

    This is the code I have:
    
    <?php
       session_start();
       if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
          // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
          unset($_SESSION['security_code']);
    	
    $message = "
    Groupon Voucher Code: {$_POST['voucher']} 
    Groupon Security Code: {$_POST['security']} 
    Centre: {$_POST['centre']} 
    First Name: {$_POST['firstname']} 
    Sur Name: {$_POST['surname']} 
    Email: {$_POST['email']} 
    Preffered Time: {$_POST['preferredtime']} 
    Additional Comments: {$_POST['comments']}
    ";
    		
    $recipient = "email@domain.co.uk";
    $subject = "Contact Form Subject";
    $mailheader = "From: {$_POST['email']}";
    
    mail($recipient, $subject, $message, $mailheader) or die ("Failure");
    		
       } 
       
       else {
    		sleep(2); 
    		header("location:failure.html");
       }
         
    ?>
    
    Code (markup):
    Looking forward to some favorable responses.

    Thanks
     
    Adnan959, Mar 10, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    just use mail function for him too...
    <?php
       session_start();
       if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
          // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
          unset($_SESSION['security_code']);
    	
    $message = "
    Groupon Voucher Code: {$_POST['voucher']} 
    Groupon Security Code: {$_POST['security']} 
    Centre: {$_POST['centre']} 
    First Name: {$_POST['firstname']} 
    Sur Name: {$_POST['surname']} 
    Email: {$_POST['email']} 
    Preffered Time: {$_POST['preferredtime']} 
    Additional Comments: {$_POST['comments']}
    ";
    		
    $recipient = "email@domain.co.uk";
    $subject = "Contact Form Subject";
    $mailheader = "From: {$_POST['email']}";
    
    mail($recipient, $subject, $message, $mailheader) or die ("Failure");
    mail($_POST['email'], "Thank you for ....", "Thanks :)", "From: youremail@adress.com");
    		
       } 
       
       else {
    		sleep(2); 
    		header("location:failure.html");
       }
         
    ?>
    PHP:
     
    G3n3s!s, Mar 10, 2011 IP
  3. Adnan959

    Adnan959 Member

    Messages:
    894
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    35
    #3
    Great! Thanks a lot :)

    Just going to test it out.
     
    Adnan959, Mar 11, 2011 IP