Results 1 to 4 of 4

Thread: Forms!

  1. #1
    Marmoset Warrior
    Join Date
    Feb 2004
    Location
    Hastings
    Posts
    1,390
    Thanks
    3
    Thanked
    0 times in 0 posts

    Forms!

    Trying to make a kind of submission form, don't want to use "action="mailto:...."" but I want a script to just e-mail me the contents.

    Preferably PHP, could anyone show me an example of one (or even flesh one out for me)

    Cheers

  2. #2
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    PHP Code:
    <?php
    //email address
    $contact_emails = array(
    array(
    'webmaster@example.net''Webmaster 1'),
    array(
    'sales@example.net''Sales 2'),
    );
    if(!
    $action)
    {
    echo 
    "Contact Us\n";
    echo 
    "\n";
    echo 
    "<form action='contact.php?action=send' method='post'>\n";
    echo 
    "Person to Contact:\n";
    $list '<select name="contact">';
    foreach(
    $contact_emails as $key=>$value) {
    $list .= '<option value="'$key .'">'$value[1] .'</option>';
    }
    $list .= '</select>';
    echo 
    $list;
    echo 
    "<br>\n";
    echo 
    "Full Name: <input type='text' name='name'>\n";
    echo 
    "Email Address:> <input type='text' name='email'><br>\n";
    echo 
    "Message:\n";
    echo 
    "<br><textarea name='msg' cols='30' rows='5'></textarea>\n";
    echo 
    "<br><input type='submit' name='submit' value='Contact me'>";
    }
    elseif(
    $action==send)
    {
    if(!
    $_POST[name])
    {
    print(
    "ERROR: Please enter name field<br>");
    }
    if(!
    $_POST[email])
    {
    print(
    "ERROR: Please enter email field<br>");
    }
    if(!
    $_POST[msg])
    {
    print(
    "ERROR: Please enter message field<br>");
    }
    elseif((
    $_POST[name])&&($_POST[email])&&($_POST[msg])==!NULL)
    {
    print(
    "Message sent,Thank you!");
    $re "Online Contact Form";
    $msg "FROM: $_POST[name]
    $_POST[msg]";
    $headers .= "From: $_POST[email] \r\n";
    $myemail $contact_emails[$_POST['contact']][0];
    mail($myemail,$re,$msg$headers);
    }
    }
    ?>
    Last edited by Barry; 05-12-2004 at 11:34 PM.
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  3. #3
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    I haven't had a chance to properly look at the code but a few tips
    - you don't need a separate echo for every line
    - it is better to enclose echo statements in single quote unless you are creating a SQL query as it's faster for PHP to parse
    - HTML parameters should be enclosed in double quotes to comply with W3C guidelines, not single quotes
    - Close tags to make it XHMTL compliant e.g. <br> should be <br />
    - No need for two arrays, use the key and value
    - Don't echo your success message until you've actually sent the mail !

    So you could end up with

    PHP Code:
    <?php
        
    //email address
        
    $contact_emails = array(
        
    'webmaster@example.net' => 'Webmaster 1'
        
    'sales@example.net' => 'Sales 2');
        
        if(!
    $action)
        {
            echo 
    'Contact Us\n\n
            <form action="contact.php?action=send" method="post">\n
            Person to Contact:\n
            <select name="contact">'
    ;
            foreach(
    $contact_emails as $key => $value
            {
                echo 
    '<option value="'$key .'">'$value .'</option>';
            }
            echo 
    '</select>
            <br />\n
            Full Name: <input type="text" name="name">\n
            Email Address: <input type="text" name="email"><br>\n
            Message:\n
            <br /><textarea name="msg" cols="30" rows="5"></textarea>\n
            <br /><input type="submit" name="submit" value="Contact me">'
    ;
        } elseif(
    $action=='send') {
            
    $fields = array('name'=>'name''email'=>'email''msg'=>'message');
            
    $errorFound 'no';
            foreach (
    $fields as $key => $value)
            {
                if (!
    $_POST[$key])
                {
                    echo 
    'ERROR: Please enter '.$value.' field<br />';
                    
    $errorFound 'yes';
                }
            }
            if (
    $errorFound == 'no')
            {
                
    $re 'Online Contact Form';
                
    $msg 'FROM: '.$_POST['name'].$_POST['msg'];
                
    $headers 'From: $_POST[email] \r\n';
                
    $myemail $contact_emails[$_POST['contact']];
                if (
    mail($myemail,$re,$msg$headers))
                {
                       echo 
    'Message sent, Thank you!';
                } else {
                       echo 
    'There was an error sending your mail';
                }; 
            }
        }
    ?>
    The best way to do this is via a class. I can recommend phpmailer as a useful option

  4. #4
    Marmoset Warrior
    Join Date
    Feb 2004
    Location
    Hastings
    Posts
    1,390
    Thanks
    3
    Thanked
    0 times in 0 posts
    PHP Code:
       <form action="mailto:recruit@lanrevolutionary.net" method="post" name="recruit" id="recruit">
       <
    table width="500" borders="0" style="text-align: left;">
         <
    tr>
           <
    td><b>Real Name:</b></td>
           <
    td><input type="text" name="name" id="name" size="20" maxlength="30" /></td>
         </
    tr>
         <
    tr>
           <
    td><b>Player Name:</b></td>
           <
    td><input type="text" name="player" id="player" size="20" maxlength="30" /></td>
         </
    tr>
         <
    tr>
           <
    td><b>Gender:</b><br /></td>
           <
    td><input type="radio" name="male" id="male" value="male" checked="checked" />Male<br />
           <
    input type="radio" name="female" id="female" value="female" />Female</td>
         </
    tr>
         <
    tr>
           <
    td><b>E-mail Address:</b></td>
           <
    td><input type="text" name="email" id="email" size="30" maxlength="30" /></td>
         </
    tr>
         <
    tr>
           <
    td><b>Verify E-mail:</b></td>
           <
    td><input type="text" name="vemail" id="vemail" size="30" maxlength="30" /></td>
         </
    tr>
         <
    tr>
           <
    td><b>MSN Messenger Address:</b></td>
           <
    td><input type="text" name="vemail" id="vemail" size="30" maxlength="30" /></td>
         </
    tr>
         <
    tr>
           <
    td><b>Recruiting Status</b></td>
           <
    td><input type="radio" name="try" id="try" value="try" checked="checked" />Trying Out<br />
           <
    input type="radio" name="rec" id="rec" value="recruited" />Previously Recruited</td>
         </
    tr>
         <
    tr>
           <
    td>Please enter the name of who recruited you (If applicable)</td>
           <
    td><select name="recruiter" id="recruiter">
                 <
    option>R1zeeK</option>
                 <
    option>Ghost</option>
                 <
    option>SgtFynmore</option>
                 <
    option>Spiers</option>
                 <
    option>Phoenix</option>
                 <
    option>Other</option>
               </
    select></td>
         </
    tr>
         <
    tr>
           <
    td><b>Name of other (If applicable):</b></td>
           <
    td><input type="text" name="vemail" id="vemail" size="30" maxlength="30" /></td>
         </
    tr>
       </
    table><br />
       <
    input type="submit" value="Recruit" />
       <
    input type="reset" value="Reset Form" />
       </
    form
    That's what I currently have, all that needs to happen is all that info needs to be e-mailed to 1 address (currently in the action= attribute of the form)

    Everything else needs to be laid out just like:
    Name:
    E-mail:
    etc..

    Something like that, find it quite tricky to understand all that PHP (but I roughly get it)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Any Martial artists here?
    By TiG in forum General Discussion
    Replies: 48
    Last Post: 01-09-2004, 10:15 PM
  2. Where to buy trade stock?
    By Allen in forum General Discussion
    Replies: 25
    Last Post: 24-01-2004, 03:31 AM
  3. more VBA and SQL 'problems'...
    By streetster in forum Software
    Replies: 7
    Last Post: 07-01-2004, 10:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •