Contact form help

  • Skrillz1
  • Born
  • Born
  • Skrillz1
  • Posts: 1

Post 3+ Months Ago

I made the php from something I found on here, but I'm really confused on how to make these two work together.



HTML Code: [ Select ]
 <h3>Contact Form</h3>
                        <form id="contact-form" method="post" enctype="multipart/form-data" action="contact.php">                    
                            <fieldset>
                                  <label><span class="text-form">Your Name:</span><input type="text"></label>
                                  <label><span class="text-form">Your Email:</span><input type="text"></label>                              
                                  <div class="wrapper">
                                    <div class="text-form">Your Message:</div>
                                    <div class="extra-wrap">
                                        <textarea></textarea>
                                        <div class="clear"></div>
                                        <div class="buttons">
                                            <a class="button" onClick="document.getElementById('contact-form').reset()"><span>clear</span></a>
                                            <a class="button" onClick="document.getElementById('contact-form').submit()"><span>send</span></a>
                                        </div>
                                    </div>
                                  </div>                            
                            </fieldset>                  
                        </form>
 
  1.  <h3>Contact Form</h3>
  2.                         <form id="contact-form" method="post" enctype="multipart/form-data" action="contact.php">                    
  3.                             <fieldset>
  4.                                   <label><span class="text-form">Your Name:</span><input type="text"></label>
  5.                                   <label><span class="text-form">Your Email:</span><input type="text"></label>                              
  6.                                   <div class="wrapper">
  7.                                     <div class="text-form">Your Message:</div>
  8.                                     <div class="extra-wrap">
  9.                                         <textarea></textarea>
  10.                                         <div class="clear"></div>
  11.                                         <div class="buttons">
  12.                                             <a class="button" onClick="document.getElementById('contact-form').reset()"><span>clear</span></a>
  13.                                             <a class="button" onClick="document.getElementById('contact-form').submit()"><span>send</span></a>
  14.                                         </div>
  15.                                     </div>
  16.                                   </div>                            
  17.                             </fieldset>                  
  18.                         </form>
  19.  




PHP Code: [ Select ]
    <?php
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_message = $_POST['cf_message'];
     
    $mail_to = '#';
    $subject = 'Message from a site visitor '.$field_name;
     
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;
     
    $headers = 'From: '.$cf_email."\r\n";
    $headers .= 'Reply-To: '.$cf_email."\r\n";
     
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
     
    if ($mail_status) { ?>
       <script language="javascript" type="text/javascript">
          alert('Thank you for the message. We will contact you shortly.');
          window.location = 'contact_page.html';
       </script>
    <?php
    }
    else { ?>
       <script language="javascript" type="text/javascript">
          alert('Message failed. Please, send an email to #');
          window.location = 'contact_page.html';
       </script>
    <?php
    }
    ?>
 
  1.     <?php
  2.     $field_name = $_POST['cf_name'];
  3.     $field_email = $_POST['cf_email'];
  4.     $field_message = $_POST['cf_message'];
  5.      
  6.     $mail_to = '#';
  7.     $subject = 'Message from a site visitor '.$field_name;
  8.      
  9.     $body_message = 'From: '.$field_name."\n";
  10.     $body_message .= 'E-mail: '.$field_email."\n";
  11.     $body_message .= 'Message: '.$field_message;
  12.      
  13.     $headers = 'From: '.$cf_email."\r\n";
  14.     $headers .= 'Reply-To: '.$cf_email."\r\n";
  15.      
  16.     $mail_status = mail($mail_to, $subject, $body_message, $headers);
  17.      
  18.     if ($mail_status) { ?>
  19.        <script language="javascript" type="text/javascript">
  20.           alert('Thank you for the message. We will contact you shortly.');
  21.           window.location = 'contact_page.html';
  22.        </script>
  23.     <?php
  24.     }
  25.     else { ?>
  26.        <script language="javascript" type="text/javascript">
  27.           alert('Message failed. Please, send an email to #');
  28.           window.location = 'contact_page.html';
  29.        </script>
  30.     <?php
  31.     }
  32.     ?>
  33.  
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

you need to give your inputs, selects and text areas names

HTML Code: [ Select ]
 
<!-- Change -->
<label><span class="text-form">Your Name:</span><input type="text"></label>
<label><span class="text-form">Your Email:</span><input type="text"></label>
<textarea></textarea>
 
 
<!-- To -->
<label><span class="text-form">Your Name:</span><input type="text" name="cf_name"></label>
<label><span class="text-form">Your Email:</span><input type="text" name="cf_email"></label>
<textarea name="cf_message"></textarea>
 
 
  1.  
  2. <!-- Change -->
  3. <label><span class="text-form">Your Name:</span><input type="text"></label>
  4. <label><span class="text-form">Your Email:</span><input type="text"></label>
  5. <textarea></textarea>
  6.  
  7.  
  8. <!-- To -->
  9. <label><span class="text-form">Your Name:</span><input type="text" name="cf_name"></label>
  10. <label><span class="text-form">Your Email:</span><input type="text" name="cf_email"></label>
  11. <textarea name="cf_message"></textarea>
  12.  
  13.  


In your PHP file make sure that you set your $mail_to = '#'; to the email address that it get sent to.

your PHP email headers are incorrect as well
PHP Code: [ Select ]
 
/* Change */
$headers = 'From: '.$cf_email."\r\n";
$headers .= 'Reply-To: '.$cf_email."\r\n";
 
/* To */
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
 
 
  1.  
  2. /* Change */
  3. $headers = 'From: '.$cf_email."\r\n";
  4. $headers .= 'Reply-To: '.$cf_email."\r\n";
  5.  
  6. /* To */
  7. $headers = 'From: '.$field_email."\r\n";
  8. $headers .= 'Reply-To: '.$field_email."\r\n";
  9.  
  10.  
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

How so? The original post yes the user is/was looking for help to make the form work. The fixes based on the original post were based on the information provided there were no name attributes to determine what information is what on the PHP side of the contact form as well as the PHP had some issues regarding variables. At the end is a working proof of concept based on the provided info.

So the name="cf_name" name="cf_email" name="cf_message" were added to the HTML inputs and textarea. these names were derived based on the PHP page the user had been working with and that is being utilized in lines 02 03 04 and used at lines 09 10 11 to build the message.

As far as the changes made to the PHP the variable $cf_email Has, at least not provided, not been set nor the $_POST been extracted. However the variable $field_email has been at line 03 and of course the $mail_to variable needs to be provided to send the contact email to whomever receives inbound emails from the site.

Proof of Concept
index.html
HTML Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
</head>
 
<body>
<h3>Contact Form</h3>
<form id="contact-form" method="post" enctype="multipart/form-data" action="contact.php">                    
    <fieldset>
        <label><span class="text-form">Your Name:</span><input type="text" name="cf_name"></label>
        <label><span class="text-form">Your Email:</span><input type="text" name="cf_email"></label>
        <div class="wrapper">
         <div class="text-form">Your Message:</div>
         <div class="extra-wrap">
            <textarea name="cf_message"></textarea>  
            <div class="clear"></div>
            <div class="buttons">
                    <a class="button" onClick="document.getElementById('contact-form').reset()"><span>clear</span></a>
                    <a class="button" onClick="document.getElementById('contact-form').submit()"><span>send</span></a>
            </div>
         </div>
        </div>                            
    </fieldset>                  
</form>
</body>
</html>
 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Contact</title>
  6. </head>
  7.  
  8. <body>
  9. <h3>Contact Form</h3>
  10. <form id="contact-form" method="post" enctype="multipart/form-data" action="contact.php">                    
  11.     <fieldset>
  12.         <label><span class="text-form">Your Name:</span><input type="text" name="cf_name"></label>
  13.         <label><span class="text-form">Your Email:</span><input type="text" name="cf_email"></label>
  14.         <div class="wrapper">
  15.          <div class="text-form">Your Message:</div>
  16.          <div class="extra-wrap">
  17.             <textarea name="cf_message"></textarea>  
  18.             <div class="clear"></div>
  19.             <div class="buttons">
  20.                     <a class="button" onClick="document.getElementById('contact-form').reset()"><span>clear</span></a>
  21.                     <a class="button" onClick="document.getElementById('contact-form').submit()"><span>send</span></a>
  22.             </div>
  23.          </div>
  24.         </div>                            
  25.     </fieldset>                  
  26. </form>
  27. </body>
  28. </html>
  29.  


contact.php
PHP Code: [ Select ]
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
 
$mail_to = 'YOUR.EMAIL@SOMESERVER.com';
$subject = 'Message from a site visitor '.$field_name;
 
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
 
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
 
$mail_status = mail($mail_to, $subject, $body_message, $headers);
 
if ($mail_status) { ?>
   <script language="javascript" type="text/javascript">
     alert('Thank you for the message. We will contact you shortly.');
     window.location = 'index.html';
   </script>
<?php
}
else { ?>
   <script language="javascript" type="text/javascript">
     alert('Message failed. Please, send an email to #');
     window.location = 'index.html';
   </script>
<?php
}
?>
 
  1. <?php
  2. $field_name = $_POST['cf_name'];
  3. $field_email = $_POST['cf_email'];
  4. $field_message = $_POST['cf_message'];
  5.  
  6. $mail_to = 'YOUR.EMAIL@SOMESERVER.com';
  7. $subject = 'Message from a site visitor '.$field_name;
  8.  
  9. $body_message = 'From: '.$field_name."\n";
  10. $body_message .= 'E-mail: '.$field_email."\n";
  11. $body_message .= 'Message: '.$field_message;
  12.  
  13. $headers = 'From: '.$field_email."\r\n";
  14. $headers .= 'Reply-To: '.$field_email."\r\n";
  15.  
  16. $mail_status = mail($mail_to, $subject, $body_message, $headers);
  17.  
  18. if ($mail_status) { ?>
  19.    <script language="javascript" type="text/javascript">
  20.      alert('Thank you for the message. We will contact you shortly.');
  21.      window.location = 'index.html';
  22.    </script>
  23. <?php
  24. }
  25. else { ?>
  26.    <script language="javascript" type="text/javascript">
  27.      alert('Message failed. Please, send an email to #');
  28.      window.location = 'index.html';
  29.    </script>
  30. <?php
  31. }
  32. ?>
  33.  

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.