www.webdeveloper.com
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2010
    Posts
    16

    resolved [RESOLVED] problem with contact form email form send_form_email.php



    i have a problem with my contact form. Everything seemed to work just fine, than i found two problems; the checkbox i inserted doesn't work yet, same as the subject. When i receive emails, they stay blanco. I have tried all kind of things but i still don't know what to do. I don't know much about HTML and I don't know how to change the code so it will work. I used a standard contact form I found on the internet... i changed a few things (I added 'subject' instead of 'telephone', I deleted 'last name', etc. and I added a checkbox...) I know I messed with the code..., but I seriously don't know how to fix it and make it work... hope someone can help me out.. already many thanks!

    This is my contact page:

    HTML Code:
    	  <div id="Layer28">
    	   <form name="contactform" method="post" action="send_form_email.php">
    <table width="450px">
    </tr>
    <tr>
     <td valign="top">
      <label for="first_name"><span class="style9">Name </span></label></td>
     <td valign="top">
      <input  type="text" name="first_name" maxlength="50" size="53"> </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="email"><span class="style9">Email Address</span></label></td>
     <td valign="top">
      <input  type="text" name="email" maxlength="80" size="53"> </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="telephone"><span class="style9">Subject</span></label></td>
     <td valign="top">
      <input  type="text" name="telephone" maxlength="30" size="53"> </td>
    </tr>
    <tr>
     <td height="135" valign="top">
      <label for="comments"><span class="style10">Message</span></label></td>
     <td valign="top">
      <textarea  name="comments" cols="40" rows="5"></textarea>
      <span style="text-align:center">
      <label>
       <br />
       <input type="checkbox" name="checkbox2" value="checkbox" />
      </label>
      <span class="style9">i want to receive the newsletter </span></span> </td>
    </tr>
    <tr>
     <td colspan="2" style="text-align:right">
      <label></label>
      <a href=""></a>  <input name="submit" type="submit" value="send" /></td>
    </tr>
    </table>
    </form>
    	  </div>
    	  <div id="Layer29">
    	    <table width="250">
              <tr>
                <td><p class="style8"><img src="contactinformation.png" alt="" width="159" height="216" /> </p>
                </td>
              </tr>
            </table>
    	  </div>
    this is my php code (send_form_email.php):

    PHP Code:
    <?php
    if(isset($_POST['email'])) {
         
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
        
    $email_to "*****";
        
    $email_subject "******";
         
         foreach(
    $_POST['check'] as $value) {

    $check_msg .= "Checked: $value\n";

    }
      
         
        function 
    died($error) {
            
    // your error code can go here
            
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo 
    "These errors appear below.<br /><br />";
            echo 
    $error."<br /><br />";
            echo 
    "Please go back and fix these errors.<br /><br />";
            die();
        }
         
        
    // validation expected data exists
        
    if(!isset($_POST['first_name']) ||
            !isset(
    $_POST['email']) ||
            !isset(
    $_POST['comments'])) {
            
    died('We are sorry, but there appears to be a problem with the form you submitted.');      
        }
         
        
    $first_name $_POST['first_name']; // required
        
    $email_from $_POST['email']; // required
        
    $comments $_POST['comments']; // required
         
        
    $error_message "";
        
    $email_exp "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!
    eregi($email_exp,$email_from)) {
        
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        
    $string_exp "^[a-z .'-]+$";
      if(!
    eregi($string_exp,$first_name)) {
        
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      }
      
      if(
    strlen($comments) < 2) {
        
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      if(
    strlen($error_message) > 0) {
        
    died($error_message);
      }
     
         
        function 
    clean_string($string) {
          
    $bad = array("content-type","bcc:","to:","cc:","href");
          return 
    str_replace($bad,"",$string);
        }
         
        
    $email_message .= "First Name: ".clean_string($first_name)."\n";
        
    $email_message .= "Email: ".clean_string($email_from)."\n";
        
    $email_message .= "Subject: ".clean_string($Subject)."\n";
        
    $email_message .= "Comments: ".clean_string($comments)."\n";
        
    $email_message .= $_POST['newsletter'] == "unscribe" "Newsletter Unsubscribe: Yes \n" "Newsletter Unsubscribe: No \n";

         
    // create email headers
    $headers 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' phpversion();
    @
    mail($email_to$email_subject$email_message$headers); 
    ?>

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    855
    OK I tested this one out.
    You need to replace these lines with your information:
    $email_to = "[your email address goes here]";
    $email_subject = "[this is the subject line that will show up in your inbox]";

    HTML Code:
    	  <div id="Layer28">
    	   <form name="contactform" method="post" action="send_form_email.php">
    <table width="450px">
    </tr>
    <tr>
     <td valign="top">
      <label for="first_name"><span class="style9">Name </span></label></td>
     <td valign="top">
      <input  type="text" name="name" maxlength="50" size="53"> </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="email"><span class="style9">Email Address</span></label></td>
     <td valign="top">
      <input  type="text" name="email" maxlength="80" size="53"> </td>
    </tr>
    <tr>
     <td valign="top">
      <label for="telephone"><span class="style9">Subject</span></label></td>
     <td valign="top">
      <input  type="text" name="subject" maxlength="30" size="53"> </td>
    </tr>
    <tr>
     <td height="135" valign="top">
      <label for="comments"><span class="style10">Message</span></label></td>
     <td valign="top">
      <textarea  name="message" cols="40" rows="5"></textarea>
      <span style="text-align:center">
      <label>
       <br />
       <input type="checkbox" name="newsletter" value="checkbox" />
      </label>
      <span class="style9">i want to receive the newsletter </span></span> </td>
    </tr>
    <tr>
     <td colspan="2" style="text-align:right">
      <label></label>
      <a href=""></a>  <input name="submit" type="submit" value="send" /></td>
    </tr>
    </table>
    </form>
    	  </div>
    	  <div id="Layer29">
    	    <table width="250">
              <tr>
                <td><p class="style8"><img src="contactinformation.png" alt="" width="159" height="216" /> </p>
                </td>
              </tr>
            </table>
    	  </div>

    PHP Code:
    <?php
    if(isset($_POST['email'])) {
         
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
        
    $email_to "[your email address goes here]";
        
    $email_subject "[this is the subject line that will show up in your inbox]";
         
        if (isset(
    $_POST['newsletter'])) {
        
    $check_msg "i want to receive the newsletter";
        } else {
        
    $check_msg "";
        }
    }
      
         
        function 
    died($error) {
            
    // your error code can go here
            
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo 
    "These errors appear below.<br /><br />";
            echo 
    $error."<br /><br />";
            echo 
    "Please go back and fix these errors.<br /><br />";
            die();
        }
         
        
    // validation expected data exists
        
    if(!isset($_POST['name']) ||
            !isset(
    $_POST['email']) ||
            !isset(
    $_POST['message'])) {
            
    died('We are sorry, but there appears to be empty fields in the form you submitted.');      
        }
         
        
    $name $_POST['name']; // required
        
    $email_from $_POST['email']; // required
        
    $message $_POST['message']; // required
        
    $subject $_POST['subject'];
         
        
    $error_message "";
        
    $email_exp "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!
    eregi($email_exp,$email_from)) {
        
    $error_message .= 'The email address you entered does not appear to be valid.<br />';
      }
        
    $string_exp "^[a-z .'-]+$";
      if(!
    eregi($string_exp,$name)) {
        
    $error_message .= 'The name you entered does not appear to be valid.<br />';
      }
      
      if(
    strlen($message) < 2) {
        
    $error_message .= 'The message you entered do not appear to be valid.<br />';
      }
      if(
    strlen($error_message) > 0) {
        
    died($error_message);
      }

         
        function 
    clean_string($string) {
          
    $bad = array("content-type","bcc:","to:","cc:","href");
          return 
    str_replace($bad,"",$string);
        }
         
        
    $email_message .= "Name: ".clean_string($name)."\n";
        
    $email_message .= "Email: ".clean_string($email_from)."\n";
        
    $email_message .= "Subject: ".clean_string($subject)."\n";
        
    $email_message .= "Message/Comments: ".clean_string($message)."\n";
        
    $email_message .= $check_msg;

         
    // create email headers
    $headers 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' phpversion();
    mail($email_to$email_subject$email_message$headers);
    ?>

  3. #3
    Join Date
    Apr 2010
    Posts
    16
    it doesn't seem to work yet

  4. #4
    Join Date
    Apr 2010
    Posts
    16
    i tried everything.. but now all the fields stay empty..

  5. #5
    Join Date
    Apr 2010
    Posts
    16
    it works now! i finally found out how it works... thanks for your help!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

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
HTML5 Development Center



Recent Articles