Forms on webpages

Discussion in 'Programming' started by diskwizz, Oct 31, 2007.

  1. #1
    Could anybody out there please explain teh simplest way for me to have my form data sent directly to me without using the mailto: option. The mailto: option kicks the outlook express into action and I know a lot of people dont use that nowadays due to hotmail/gmail etc.
    I was looking for an option where my form is filled in and when they hit submit it just pings over to me without the need for their email client to kick in.
    ANy options much appreciated, with a step by step guide of course :)
    Thanks in advance.
    DW
     
    diskwizz, Oct 31, 2007 IP
  2. rile

    rile Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    One of the simplest ways is to use PHP. When you make a form with method post and action is i.e. send.php. In that php file you must get all that POST variables (fields in your form), formating and send with mail function.
     
    rile, Oct 31, 2007 IP
  3. diskwizz

    diskwizz Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    I may sound arrogant here. But could you explain that in simple terms pls. Is there a webpage with step by step guide etc?
    Thanks

    EDIT: I have just been thinking and wondered if php would be any use as the page is already built in html. To give you and idea of whatI want here is the test page in question. praiadarochaonline.com/castelosdarochatest.html the form is at the bottom of the page and I would rather the info is just filled in and then pinged to me rather than opening somebodies mail client etc.
    Any suggestions most welcome.

    Thanks again, DW.
     
    diskwizz, Oct 31, 2007 IP
  4. rile

    rile Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    From your question I see that HTML and PHP are not familiar to you, anyway i'll give you some details:

    1. You must define what user should enter. Let say email, name and comment.
    2. Make form:
    
    <FORM METHOD="POST" ACTION="send.php">
    <H2>Please post your comment</H2>
    <BR>
    Name: <INPUT TYPE="TEXT" NAME="username">
    <BR>
    E-mail: <INPUT TYPE="TEXT" NAME="useremail">
    <BR>
    Comment: <BR>
    <TEXTAREA NAME="usercomment" ROWS="7" COLS="35"></TEXTAREA>
    <BR>
    <INPUT TYPE="SUBMIT" VALUE="sendemail">
    </FORM>
    
    Code (markup):
    3. Put this form on your page

    4. Make send.php and put this into:
    
    <HTML>
    <HEAD>
    <TITLE>Sending e-mail</TITLE>
    </HEAD>
    <BODY>
    <?php
    $username=$HTTP_POST_VARS["username"];
    $usermail=$HTTP_POST_VARS["usermail"];
    $usercomment=$HTTP_POST_VARS["usercomment"];
    $mail_from="your.site@email.address";
    $mail_to="your@email.address";
    $mail_subj="New comment";
    $mail_body="User: $username \n From: $usermail \n Posted comment: $usercomment";
    mail(trim($mail_to),trim($mail_subj),$mail_body,"From: ".trim($mail_from));
    ?>
    <H2>Your data sent</H2>
    </BODY>
    </HTML>
    
    Code (markup):
    Change values of $mail_from,$mail_to,$mail_subj,$mail_body to fit your needs, and upload this file to server.
    This file must be in the same directory as html file with form, in other case change ACTION value on form to proper path.

    Of course this is general answer, and you must edit it to fit your needs.
     
    rile, Oct 31, 2007 IP
  5. rhartj01

    rhartj01 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Check out these links

    http://www.tizag.com/phpT/forms.php

    http://www.w3schools.com/php/php_forms.asp
     
    rhartj01, Oct 31, 2007 IP
  6. diskwizz

    diskwizz Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #6
    Interesting links. Much appreciated.
     
    diskwizz, Nov 1, 2007 IP
  7. diskwizz

    diskwizz Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #7
    Thanks rile. Have used teh code but when the mail comes thru it doesnt have the email address attached.
     
    diskwizz, Nov 1, 2007 IP
  8. rile

    rile Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    Yes, I see error. My mistake...

    Line:
    
    $usermail=$HTTP_POST_VARS["usermail"];
    
    Code (markup):
    change into
    
    $usermail=$HTTP_POST_VARS["useremail"];
    
    Code (markup):
    try now... other fields ok?
     
    rile, Nov 1, 2007 IP
  9. diskwizz

    diskwizz Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #9
    Have to be honest, I cant even spot the change but it works lol. Ill just add my own little bits to it and it will do the job just right for me.
    Your help is much appreciated. Is nice to be given an answer rather than a quote to do the work on my behalf. ;)
     
    diskwizz, Nov 2, 2007 IP
  10. diskwizz

    diskwizz Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #10
    Sorry to be a pain again. BUT. Once it goes to the "YOUR DATA SENT" page I would like to have a link on there to enable people to get back to the main site.
    What would be the code for this?
    Thanks again, DW
     
    diskwizz, Nov 2, 2007 IP
  11. rile

    rile Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #11
    You can do something like this:

    send.php
    
    <?php
    $username=$HTTP_POST_VARS["username"];
    $usermail=$HTTP_POST_VARS["useremail"];
    $usercomment=$HTTP_POST_VARS["usercomment"];
    $mail_from="your.site@email.address";
    $mail_to="your@email.address";
    $mail_subj="New comment";
    $mail_body="User: $username \n From: $usermail \n Posted comment: $usercomment";
    mail(trim($mail_to),trim($mail_subj),$mail_body,"From: ".trim($mail_from));
    header( 'Location: http://www.your_site.com/your_page.html' );
    ?>
    
    Code (markup):

    Note that html tags aren't in send.php, send.php execute and redirect to http://www.your_site.com/your_page.html
     
    rile, Nov 2, 2007 IP