Results 1 to 7 of 7

Thread: Help with contact form please

  1. #1
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with contact form please

    ok i used dreamweaver to create a contact form for one of my webpage but i don't know how you get it to send me the emails from the form could some one help me please

    here is the code

    Code:
    <form id="form1" name="advertising" method="post" action="">
                    <table width="100%" align="center">
                    <tr>
                      <td width="92">Name</td>
                      <td width="158"><label>
                        <input name="your_name" type="text" id="your_name" size="45" maxlength="45" />
                      </label></td>
                    </tr>
                    <tr>
                      <td>Company Name</td>
                      <td><label>
                        <input name="company_name" type="text" id="company_name" size="45" maxlength="45" />
                      </label></td>
                    </tr>
                    <tr>
                      <td>Email Address</td>
                      <td><label>
                        <input name="email_address" type="text" id="email_address" size="45" maxlength="45" />
                      </label></td>
                    </tr>
                    <tr>
                      <td><p>Banner Option</p>                  </td>
                      <td><label>
                        <select name="banner_options" class="text2" id="banner_options">
                          <option>Text Links</option>
                          <option>Banner1</option>
                          <option>Banner2</option>
                          <option>Banner3</option>
                        </select>
                      </label></td>
                    </tr>
                    <tr>
                      <td>Other Comments</td>
                      <td><label>
                        <textarea name="other_comments" id="other_comments" cols="57" rows="11"></textarea>
                      </label></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><label>
                        <input name="button" type="submit" class="inputstyle" id="button" onclick="MM_validateForm('your_name','','R','company_name','','R','email_address','','RisEmail','other_comments','','R');return document.MM_returnValue" value="Send" />
                      </label>
                        <label>
                        <input name="button2" type="reset" class="inputstyle" id="button2" value="Clear" />
                      </label></td>
                    </tr>
                  </table>
                </form>

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That form is fine.

    However, you need to get the data sent to something.

    action determines the location to which the data is sent.

    At the moment action="" submits the data to the current page, reloading it.

    PHP can interpret form data, as can other server side programming languages. You could use one of these, and it would be the best, but also hardest, option.

    Secondly, you could submit (using action) to a free form mailer, that would mail directly to you, through their page. This usually ends up with some ads, and also less control for you. Easier and still fairly good option, though.

    The worst, though extremely easy, idea is using action="mailto:me@my.com". That will use the default email client for the visitor to send you an email. However, it will be awkward for the, not look professional, but, especially, not work on many computers.
    All windows computers will be default open Outlook Express, if nothing else is setup as a default computer. "Mail" opens on Macs with OSX. Not sure about linux. Maybe nothing.
    Many people, including me, don't have a default client setup, so it is just annoying.
    Much better idea to use one of the other two options.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    do you know where to i can find a tutorial to create a contact.php file?
    Last edited by cbleep; 09-13-2007 at 06:00 PM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'd say just search google for on that fits your learning style.
    From a quick glance, this one looks ok:
    http://www.kirupa.com/web/php_contact_form.htm

    You can also search the old threads here. There are lots of discussions on the subject.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i got a contact.php code but its not working here is my html code and the contact.php code can you tell me what i have done wrong please

    html code

    Code:
                   <form id="form1" name="advertising" method="post" action="contact.php">
                    <table width="100%" align="center">
                    <tr>
                      <td width="92">Name</td>
                      <td width="158"><label>
                        <input name="name" type="text" id="name" size="45" maxlength="45" />
                      </label></td>
                    </tr>
                    <tr>
                      <td>Company Name</td>
                      <td><label>
                        <input name="company" type="text" id="company" size="45" maxlength="45" />
                      </label></td>
                    </tr>
                    <tr>
                      <td>Email Address</td>
                      <td><label>
                        <input name="email" type="text" id="email" size="45" maxlength="45" />
                      </label></td>
                    </tr>
                    <tr>
                      <td><p>Banner Option</p>                  </td>
                      <td><label>
                        <select name="options" class="text2" id="options">
                          <option>Text Links</option>
                          <option>Banners</option>
                          <option>Bannerrrs</option>
                          <option>Bannnerss</option>
                        </select>
                      </label></td>
                    </tr>
                    <tr>
                      <td> Comments</td>
                      <td><label>
                        <textarea name="message" id="message" cols="57" rows="11"></textarea>
                      </label></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><label>
                        <input name="button" type="submit" class="inputstyle" id="button" onclick="MM_validateForm('name','','R','company','','R','email','','RisEmail','message','','R');return document.MM_returnValue" value="Send" />
                      </label>
                        <label>
                        <input name="button2" type="reset" class="inputstyle" id="button2" value="Clear" />
                      </label></td>
                    </tr>
                  </table>
                </form>

    contact.php

    Code:
    <?php
    
    // Custom variables - Edit these to meet your needs
    
    $email = "my@mydomain.com";
    $message = "You have been sent an e-mail via your contact form by [EMAIL]
    
    --------------------------------
    
    [MESSAGE]
    
    --------------------------------"; /* The e-mail structure you will receive. Every occurrence of [EMAIL] will be replaced by 
    
    the user's e-mail address and every occurrence of [MESSAGE] will be replaced by the user's message to you */
    $subject = "E-mail from Contact Form: [SUBJECT]" /* The subject line of all e-mails sent to you via this script. Every 
    
    occurrence of [SUBJECT] will be replaced by the user's subject. */
    
    // No more configuration variables beyond this point
    
    if ( $_POST['Send'] )
    {
    // Make sure all fields have been filled in
    
    $errors = array();
    
    if ( ! $_POST['name'] )
    {
    $errors[] = "You must enter your name in the field provided.";
    }
    
    if ( ! $_POST['company'] )
    {
    $errors[] = "You must enter your company name in the field provided.";
    }
    
    if ( ! $_POST['email'] )
    {
    $errors[] = "You must enter your e-mail address in the field provided.";
    }
    
    if ( ! $_POST['option'] )
    {
    $errors[] = "Please select a option from the drop-down list provided.";
    }
    
    if ( ! $_POST['message'] )
    {
    $errors[] = "You must enter a message to send.";
    }
    
    if ( count( $errors ) > 0 )
    {
    print "The following errors have occurred with your contact form:<br /><br />\r\n";
    
    foreach ( $errors as $msg )
    {
    print "- {$msg}<br />\r\n";
    }
    
    print "Please <a href=\"java script:history.back()\">Return</a> and fix these problems.
    }
    else
    {
    $name = $_POST['name'];
    $name = str_replace( '[NAME]', $_POST['name'], $name );
    $company = $_POST['company'];
    $campany = str_replace( '[COMPANY]', $_POST['company'], $company );
    $option = $_POST['option'];
    $option = str_replace( '[OPTION]', $_POST['option'], $option );
    $message = $_POST['message'];
    $message = str_replace( '[MESSAGE]', $_POST['message'], $message );
    $message = str_replace( '[EMAIL]', $_POST['email'], $message );
    
    
    if ( @mail( $_POST['email'], $_POST['name'], $_POST['company'], $_POST['option'], $_POST['message'], "From: {$email}" ) )
    {
    print "Your e-mail has been sent successfully.";
    }
    else
    {
    print "There seems to be a problem with sending your e-mail. Please try again at a later time.";
    }
    }
    }

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    1. you must be sure that you have php installed and available through your host.
    2. you are using the <label> in the wrong place... If you were going to use it anywhere, I would use it with the text describing the input.
    Code:
    <label>Name:</label>
    <input type="text" name="name" value="">
    3.
    if ( @mail( $_POST['email'], $_POST['name'], $_POST['company'], $_POST['option'], $_POST['message'], "From: {$email}" ) )
    you are sending the email from your email to the customer, but nothing is sent to you. also the format of the mail function is

    Code:
    mail( receipient, subject, message, headers, parameters )
    so I am assuming you would want soemthing more along the lines of

    Code:
    $email = "me@domain.com";
    $subject = "My Subject of email";
    $message = "";
    foreach($_POST as $k => $k)
    {
          $message .= $k . " - " . $v . "\r\n";
    }
    
    if( mail($email, $subject, $message, "From: $_POST['email']") )
    print "sent correctly";

  7. #7
    Join Date
    Sep 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    errrm i don't know where to start i am a newbie to coding could you help by just correcting the contact.php file for me please?

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
  •