Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: form mail script help

  1. #1
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default form mail script help

    I am not much in php can anyone create me a form mail code in php for the fields

    Name:
    Surname:
    Address: (Optional)
    Tel: (Optional)
    Reason for contact:
    Message:

    Please note the fields are in a table structure like
    __________ __________
    |__________|__________|
    |__________|__________|
    |__________|__________|

    as far as the code is there is no text infornt the field

    <input type="text" name="Name" id="Name:" value="Enter Full Name" size="25"
    maxlenght="30" />
    <input type="text" name="Surname" id="Surname:" value="Enter Full Name" size="25"
    maxlenght="30" />
    <input type="text" name="Address" id="Address" value="Address:" size="25"
    maxlenght="30" />
    <input type="text" name="Address" id="Address" value="Address" size="25"
    maxlenght="30" />
    <input type="text" name="Address" id="Address" value="Address" size="25"
    maxlenght="30" />
    <input type="text" name="Reason" id="Reason" value="Reason For Contact:" size="25"
    maxlenght="30" />
    <textarea name="textanimal" ID="textanimal" rows="5" cols="40">Message you want to send to us</textarea>
    Last edited by Mehok; 10-25-2006 at 02:43 PM.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    This is a fairly simple formmail script. It does not do any verifications or what not but you should be able to edit it by looking at PHP.net or some other websites that have PHP tutorials. Just set the HTML form action to go to contact.php and make the following page as that.

    contact.php
    PHP Code:
    <?php
    //edit the following

    $to "nobody@mydomain.com"//your email address
    $subject "Contact Form from Website"//the subject of the email


    //Get the variables

    $name $_REQUEST[Name];
    $sname $_REQUEST[Surname];
    $addr1 $_REQUEST[Address1];
    $addr2 $_REQUEST[Address2];
    $addr3 $_REQUEST[Address3];
    $reason $_REQUEST[Reason];
    $message $_REQUEST[textanimal];

    $msg = <<<HERE
    The following information was submitted from the contact form on your website.

    Name: 
    $name

    Surname: 
    $sname

    Address: 
    $addr1
                 
    $addr2
                 
    $addr3

    Reason for Contact: 
    $reason

    Message:

    $message

    HERE;

    //edit the above to be the message that is sent to you


    if (@mail($to,$subject,$msg)) {
    echo 
    'The email was sent successfully!';
    }

    else {
    echo 
    'The email was not sent because of an error!';
    }

    //thats all!!!!
    ?>
    have fun!
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    thanks i seriously cannot figure out this ****

    hopefully this will get me off to a grate start

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Just let me know if you need any help with it.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    I just got tha form uploaded it gives me a message that the form was sent but i aint getting it

  6. #6
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite
    Just let me know if you need any help with it.
    Hi There... This looks like exactly what I need but I couldn't figure out the form side? Is it easy to incorporate this into the attached form? I tried but to no avail...

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Mehok, perhaps your server does not have SMTP on it, or at least sendmail I should say. A way that you can see if it is something with the script is by changing the following line:

    PHP Code:
    if (@mail($to,$subject,$msg)) { 
    to this:

    PHP Code:
    if (mail($to,$subject,$msg)) { 
    notice I took the "@" sign from the front of mail(). This will now display any error messages if there are any errors.

    tomyknoker,

    this formmail script should work with it, all you would have to change is the first part to suit your needs.

    Example:
    PHP Code:
    //Get the variables

    $text1 $_REQUEST[textfield1];
    $text2 $_REQUEST[textfield2];
    $check1 $_REQUEST[checkbox1];
    $tarea1 $_REQUEST[textarea1];

    //add more if needed 
    the $_REQUEST['yourfieldname']; gets the value that was submitted in the form then assigns a variable for you to use in the php script.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite
    Mehok, perhaps your server does not have SMTP on it, or at least sendmail I should say. A way that you can see if it is something with the script is by changing the following line:

    PHP Code:
    if (@mail($to,$subject,$msg)) { 
    to this:

    PHP Code:
    if (mail($to,$subject,$msg)) { 
    notice I took the "@" sign from the front of mail(). This will now display any error messages if there are any errors.

    tomyknoker,

    this formmail script should work with it, all you would have to change is the first part to suit your needs.

    Example:
    PHP Code:
    //Get the variables

    $text1 $_REQUEST[textfield1];
    $text2 $_REQUEST[textfield2];
    $check1 $_REQUEST[checkbox1];
    $tarea1 $_REQUEST[textarea1];

    //add more if needed 
    the $_REQUEST['yourfieldname']; gets the value that was submitted in the form then assigns a variable for you to use in the php script.
    hi there! thanks for the info... i can't get it to work with my form any chance you could show mne the html code for the whole thing on my form? i'm getting myself really confused...

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Use the following as a start:

    contact.html
    Code:
    <html>
    <head>
    <title>Contact.html</title>
    </head>
    <body>
    
    <!--Start the form-->
    <form action="contact.php" method="POST">
    Text1: <input type="text" name="text1"> <BR>
    Text2: <input type="text" name="text2"> <BR>
    <input type="checkbox" name="checkbox1" value="check1"> Checkbox1 
    <input type="checkbox" name="checkbox2" value="check2"> Checkbox2 <BR>
    <textarea name="textarea1">This is called textarea1</textarea>
    <BR><BR>
    
    <input type="submit" value="Submit Form">
    </body>
    </html>
    contact.php

    PHP Code:
    <?php
    //edit the following

    $to "nobody@mydomain.com"//your email address
    $subject "Contact Form from Website"//the subject of the email


    //Get the variables


    $text1 $_REQUEST[text1]; //variable for form field text1
    $text2 $_REQUEST[text2]; //variable for form field text2
    $checkbox1 $_REQUEST[checkbox1]; //variable for form field checkbox1
    $checkbox2 $_REQUEST[checkbox2]; //variable for form field checkbox2
    $textarea1 $_REQUEST[textarea1]; //variable for form field textarea1

    $msg = <<<HERE
    The following information was submitted from the contact form on your website.

    Text1: 
    $text1
    Text2: 
    $text2
    Checkbox1: 
    $checkbox1
    Checkbox2: 
    $checkbox2
    Textrea1: 

    $textarea1
    HERE;

    //edit the above to be the message that is sent to you

    $sent mail($to,$subject,$msg); //try to send the message

    if ($sent) { //if the email was sent
    echo 'The email was sent successfully!';
    }

    else {  
    //if it was not sent
    echo 'The email was not sent because of an error!';
    }

    //thats all!!!!
    ?>
    That should at least be a start for you. Simply modify the two files to suit your needs.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #10
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite
    Use the following as a start:

    contact.html
    Code:
    <html>
    <head>
    <title>Contact.html</title>
    </head>
    <body>
    
    <!--Start the form-->
    <form action="contact.php" method="POST">
    Text1: <input type="text" name="text1"> <BR>
    Text2: <input type="text" name="text2"> <BR>
    <input type="checkbox" name="checkbox1" value="check1"> Checkbox1 
    <input type="checkbox" name="checkbox2" value="check2"> Checkbox2 <BR>
    <textarea name="textarea1">This is called textarea1</textarea>
    <BR><BR>
    
    <input type="submit" value="Submit Form">
    </body>
    </html>
    contact.php

    PHP Code:
    <?php
    //edit the following

    $to "nobody@mydomain.com"//your email address
    $subject "Contact Form from Website"//the subject of the email


    //Get the variables


    $text1 $_REQUEST[text1]; //variable for form field text1
    $text2 $_REQUEST[text2]; //variable for form field text2
    $checkbox1 $_REQUEST[checkbox1]; //variable for form field checkbox1
    $checkbox2 $_REQUEST[checkbox2]; //variable for form field checkbox2
    $textarea1 $_REQUEST[textarea1]; //variable for form field textarea1

    $msg = <<<HERE
    The following information was submitted from the contact form on your website.

    Text1: 
    $text1
    Text2: 
    $text2
    Checkbox1: 
    $checkbox1
    Checkbox2: 
    $checkbox2
    Textrea1: 

    $textarea1
    HERE;

    //edit the above to be the message that is sent to you

    $sent mail($to,$subject,$msg); //try to send the message

    if ($sent) { //if the email was sent
    echo 'The email was sent successfully!';
    }

    else {  
    //if it was not sent
    echo 'The email was not sent because of an error!';
    }

    //thats all!!!!
    ?>
    That should at least be a start for you. Simply modify the two files to suit your needs.
    Thanks so much! So with the form.html... What code do I put on the submit button?

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
  •