Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Contact form using php

  1. #1
    Join Date
    Apr 2008
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Contact form using php

    I want to add a contact form on to my website that enables new enquires to submit an enquiry.

    i only need name, email and a comments box

    thanks

    michael
    Last edited by biomike; 12-10-2008 at 05:52 PM. Reason: update

  2. #2
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    As you did not specify how you would like to view the comments etc. i have done it with the mail function and mysql:

    PHP Code:
    <?php
    // Thomas Golding (hmsnacker123) (C) 2008

        
    if(!$_POST['submit']){
            echo 
    "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
            echo 
    "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
            echo 
    "<tr><td>Name:&nbsp;</td><td><input type=\"text\" name=\"name\" /></td></tr>\n";
            echo 
    "<tr><td>Email:&nbsp;</td><td><input type=\"text\" name=\"email\" /></td></tr>\n";
            echo 
    "<tr><td>Comments:&nbsp;</td><td><textarea name=\"comments\" cols=\"40\" rows=\"5\"></textarea></td></tr>\n";
            echo 
    "<tr><td>Type:</td><td><select name=\"type\"><option value=\"1\">mail()</option><option value=\"2\">mysql</option></select></td></tr>\n";
            echo 
    "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Submit\" /></td></tr>\n";
            echo 
    "</form>\n";
            echo 
    "</table>";
        }else {
            
    $name $_POST['name'];
            
    $email $_POST['email'];
            
    $comments $_POST['comments'];
            
    $type $_POST['type'];
            
            if(
    $name && $email && $comments && $type){
                if(
    $type == 1){
                    
    //If you choose the mail function
                    
    $to "youremail@yourserver.com";
                    
    $subject "Contact form";
                    
    $message "You have comments off ".$name.", His/Her email is ".$email.", The comments are: ".$comments."";
                    
    mail($to$subject$message);
                }
                if(
    $type == 2){
                    
    $conn mysql_connect('localhost','username','password');
                    
    mysql_select_db('dbname'$conn);
                    
    $sql "INSERT INTO table_name (`name`,`email`,`comments`) VALUES ('$name','$email','$comments')";
                    
    $res mysql_query($sql) or die(mysql_error());
                }
                
            }else {
                echo 
    "Please supply all the fields.";
            }
            
            
            
        }


    ?>
    If the method is other than that in the script, Please tell me and I will modify the script to your requirements.

  3. #3
    Join Date
    Sep 2008
    Posts
    56
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Reply :- contact form using php

    Quote Originally Posted by biomike View Post
    I want to add a contact form on to my website that enables new enquires to submit an enquiry.

    i only need name, email and a comments box

    thanks

    michael
    Hi,

    You will have to first create a form with these fields and then download formmail.php and link to this form. If you will type ‘download formmail.php’ on Google you will get this file along with the instructions for how to use it.

    Cheers,

    ~Maneet Puri
    Lexolution IT Services
    Web Development Company

  4. #4
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    The following pages might help
    Email Form 'HowTo's
    PHP Form to email

  5. #5
    Join Date
    Apr 2008
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks hmsnacker123

    It's not working. I am not receiving the email with the details. Also when you submit the form you then go to a blank page plus i was doing it in firefox and the blank page appeared on IE.

    I have created the following form in my html document

    Code:
       <!-- STEP 1: Put the full URL to formmail.php on your website in the 'action' value. -->
    <form method="post" action="http://www.bioenergyhealing.org.uk/formmail.php" name="QuestionForm">
        <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">
        <!-- STEP 2: Put your email address in the 'recipients' value.
                     Note that you also have to allow this email address in the
                     $TARGET_EMAIL setting within formmail.php!
        -->
        <input type="hidden" name="recipients" value="msc@bioenergyhealing.org.uk" />
        <!-- STEP 3: Specify required fields in the 'required' value -->
        <input type="hidden" name="required" value="email:Your email address,name:Your name" />
        <!-- STEP 4: Put your subject line in the 'subject' value. -->
        <input type="hidden" name="subject" value="Question FormMail" />
    
    			<font class=content>                 
              <p style="margin-top: 0; margin-bottom: 0" align="center"><strong><font face="Arial" size="2">Directions:</font></strong><font face="Arial" size="2">
                            Please type in your question below, then click the&nbsp;</font></p>
              <p style="margin-top: 0; margin-bottom: 0" align="center"><font face="Arial" size="2">
     <strong>“Here's my question, Michael!”</strong>  button below.</font></p>
        </font>
    
        <table border="0" cellspacing="5%">
        <tr>
            <td valign="top" colspan="2">
    
    			<font class=content>                 
              <textarea name="mesg" rows="10" cols="50"></textarea>
        </font>
            </td>
        </tr>
        <tr>
    
    			<font class=content>                 
            <td>
            <p><font size="3" face="Arial">Please enter your name:</font></p>
            </td>
            <td><font size="3" face="Arial"><input type="text" name="name" />
              </font>
            </td>
        </font>
        </tr>
        <tr>
    
    			<font class=content>                 
            <td>
            <p><font size="3" face="Arial">Please enter your email address:</font></p>
            </td>
            <td><font size="3" face="Arial"><input type="text" name="email" />
              </font>
            </td>
        </font>
        </tr>
        <tr>
            <td colspan="2" align="center">
              <table border="1" bordercolor="#000000" bgcolor="#EC4D00">
                <tr>
                  <td bgcolor="#EC4D00" bordercolor="#EC4D00">
    
    			<font class=content>                 
              <input type="submit" value="Here's my question Michael!" />
        </font>
                  </td>
                </tr>
              </table>
            </td>
        </tr>
        </table>
    </form>
    I have updated your php code as follows called formmail.php.

    PHP Code:
    <?php
    // Thomas Golding (hmsnacker123) (C) 2008

        
    if(!$_POST['submit']){
            echo 
    "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
            echo 
    "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
            echo 
    "<tr><td>Name:&nbsp;</td><td><input type=\"text\" name=\"name\" /></td></tr>\n";
            echo 
    "<tr><td>Email:&nbsp;</td><td><input type=\"text\" name=\"email\" /></td></tr>\n";
            echo 
    "<tr><td>Question:&nbsp;</td><td><textarea name=\"mesg\" cols=\"40\" 

    rows=\"5\"></textarea></td></tr>\n"
    ;
            echo 
    "<tr><td>Type:</td><td><select name=\"type\"><option value=\"1\">mail()</option><option 

    value=\"2\">mysql</option></select></td></tr>\n"
    ;
            echo 
    "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Here's my 

    question Michael!\" /></td></tr>\n"
    ;
            echo 
    "</form>\n";
            echo 
    "</table>";
        }else {
            
    $name $_POST['name'];
            
    $email $_POST['email'];
            
    $question $_POST['question'];
            
    $type $_POST['type'];
            
            if(
    $name && $email && $question && $type){
                if(
    $type == 1){
                    
    //If you choose the mail function
                    
    $to "msc@bioenergyhealing.org.uk";
                    
    $subject "question form";
                    
    $message "You have questions ".$name.", His/Her email is ".$email.", The question are: 

    "
    .$question."";
                    
    mail($to$subject$message);
                }
               
        }


    ?>
    Thanks Michael
    Last edited by Snookerman; 12-28-2009 at 01:25 PM. Reason: please use [code] tags or [php] tags

  6. #6
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    OK:

    You might not have php mail set up.. use google to help you with this,

    as for the script, Try this out and tell me if it helps you:

    PHP Code:
    <?php
    // Thomas Golding (hmsnacker123) (C) 2008

    ob_start();

    if(!
    $_POST['submit']){

        if(isset(
    $_GET['msg']))
            echo 
    $_GET['msg'];

        echo 
    "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n";
        echo 
    "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
        echo 
    "<tr><td>Name:&nbsp;</td><td><input type=\"text\" name=\"name\" /></td></tr>\n";
        echo 
    "<tr><td>Email:&nbsp;</td><td><input type=\"text\" name=\"email\" /></td></tr>\n";
        echo 
    "<tr><td>Question:&nbsp;</td><td><textarea name=\"mesg\" cols=\"40\" rows=\"5\"></textarea></td></tr>\n";
        echo 
    "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Here's my question Michael!\" /></td></tr>\n";
        echo 
    "</form>\n";
        echo 
    "</table>";
    }else {
        
    $name       $_POST['name'];
        
    $email    $_POST['email'];
        
    $question $_POST['mesg'];

        if(
    $name && $email && $question){
            
    //If you choose the mail function
            
    $to "msc@bioenergyhealing.org.uk";
            
    $subject "question form";
            
    $message "You have questions ".$name.", His/Her email is ".$email.", The question are:".$question."";
            
    mail($to$subject$message);
        }
    }

    ob_end_flush();

    ?>

  7. #7
    Join Date
    Apr 2008
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Were getting there. I am know getting the email with the question. However the form is on the php page when i need it on the html page http://www.bioenergyhealing.org.uk/ask_a_question3. This way the visitor doesn't have to go to another page to submit.

    any suggestions

  8. #8
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    Ok well on the HTML page which is http://www.bioenergyhealing.org.uk/ask_a_question3 (I Think), I have copied the HTML for the form out of the source and changed a couple of things:
    HTML Code:
    <form method="post" action="http://www.bioenergyhealing.org.uk/formmail.php" name="QuestionForm">
    			<font class=content>                 
              <p style="margin-top: 0; margin-bottom: 0" align="center"><strong><font face="Arial" size="2">Directions:</font></strong><font face="Arial" size="2">
    
                            Please type in your question below, then click the&nbsp;</font></p>
              <p style="margin-top: 0; margin-bottom: 0" align="center"><font face="Arial" size="2">
     <strong>“Here's my question, Michael!”</strong>  button below.</font></p>
        </font>
    
        <table border="0" cellspacing="5%">
        <tr>
    
            <td valign="top" colspan="2">
    
    			<font class=content>                 
              <textarea name="mesg" rows="10" cols="50"></textarea>
        </font>
            </td>
        </tr>
        <tr>
    
    			<font class=content>                 
            <td>
    
            <p><font size="3" face="Arial">Please enter your name:</font></p>
            </td>
            <td><font size="3" face="Arial"><input type="text" name="name" />
              </font>
            </td>
        </font>
        </tr>
        <tr>
    
    			<font class=content>                 
            <td>
            <p><font size="3" face="Arial">Please enter your email address:</font></p>
            </td>
            <td><font size="3" face="Arial"><input type="text" name="email" />
              </font>
            </td>
        </font>
    
        </tr>
        <tr>
            <td colspan="2" align="center">
              <table border="1" bordercolor="#000000" bgcolor="#EC4D00">
                <tr>
                  <td bgcolor="#EC4D00" bordercolor="#EC4D00">
    
    			<font class=content>                 
              <input type="submit" name="submit" value="Here's my question Michael!" />
        </font>
    
                  </td>
                </tr>
              </table>
            </td>
        </tr>
        </table>
    </form>
    and in formail.php put:

    PHP Code:
    <?php
    // Thomas Golding (hmsnacker123) (C) 2008
    ob_start();
    if(
    $_POST['submit']){

        
    $name     $_POST['name'];
        
    $email    $_POST['email'];
        
    $question $_POST['mesg'];

        if(
    $name && $email && $question){
            
    //If you choose the mail function
            
    $to "msc@bioenergyhealing.org.uk";
            
    $subject "Question FormMail";
            
    $message "You have questions ".$name.", His/Her email is ".$email.", The question are:".$question."";
            
    mail($to$subject$message);
        
    header("Location: yoursuccesspage.html");

    }else {
        echo 
    "Please supply all the fields";
    }
    }else {
        echo 
    "Improper use of this file.";
    }
    ob_end_flush();

    ?>
    Hope that helps.

  9. #9
    Join Date
    Apr 2008
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks hmsnacker123 for all your help it works.

  10. #10
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    Thats fine, Please thank me

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
  •