Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    Member #
    32123
    I can really use a hand. I am trying to setup the contact form for my site, and I dont know PHP. The Form is basically:

    First Name*
    Email*
    Company
    Subject
    Message*

    Submit Button

    The fields with Asterisks are REQUIRED fields. I found some PHP code online but it makes no sense.

    Here is the PHP form Code

    <?php

    if(!$_POST) exit;

    $email = $_POST['email'];

    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
    }
    if($errors==1) echo $error;
    else{
    $values = array ('name','email','message');
    $required = array('name','email','message');

    $your_email = "james@example.com";
    $email_subject = "New Message: ".$_POST['subject'];
    $email_content = "new message:\n";

    foreach($values as $key => $value){
    if(in_array($value,$required)){
    if ($key != 'subject' && $key != 'company') {
    if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
    }
    $email_content .= $value.': '.$_POST[$value]."\n";
    }
    }

    if(@mail($your_email,$email_subject,$email_content )) {
    echo 'Message sent!';
    } else {
    echo 'ERROR!';
    }
    }
    ?>

    Can someone please help me figure out what to put where?

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    You have so many other issues to deal with ...

    Will there be any captcha coding to reduce spamming?
    Do the error messages need to go back to the form itself, or display on a blank white page?
    Does the form disappear after submit, or stays there with a thankyou?
    Validation using javascripting, PHP, or both? How about using AJAX?

    I really recommend you start here:
    http://www.google.com/search?q=php+a...ha&btnG=Search

    You're not going to like how your existing form is going to function.
    It displays errors on a plain white page, and the user has to go back to
    a blank form to fix their errors. No captcha, "thankyou" is on a plain
    white page.


  4. #3
    Junior Member SimplyWebsites's Avatar
    Join Date
    Jul 2012
    Location
    Leicester
    Posts
    27
    Member #
    32160
    First Name*
    Email*
    Company
    Subject
    Message*

    Submit Button

    So i'm sure you already have one but first you need to create the form. The important part is the name because this is what you will refer to in the php script which comes next.

    form.html:

    <form method="post" action="submit.php">
    <input type="text" name="firstname" />
    <input type="text" name="email" />
    <input type="text" name="company" />
    <input type="text" name="subject" />
    <textarea name="message" rows="5" cols="30"></textarea>
    <input type="submit" value="Send Message" />
    </form>

    Now that you have you form we need to create submit.php

    submit.php:

    <?
    // The email address you want messages to be sent to
    $your_email_address = "me@example.com";

    // First we need to get all the fields into variables.
    $firstname = $_POST['firstname'];
    $email = $_POST['email'];
    $company = $_POST['company'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];

    // Now lets create the email thats going to be sent to you!
    $subject = "New Contact Form Message";

    $the_email = "You have a new message from: $firstname"."\n\n";
    $the_email .= "Email: $email"."\n";
    $the_email .= "Company: $company"."\n";
    $the_email .= "Subject: $subject"."\n\n";
    $the_email .= "Message: $message"."\n\n";

    // Now lets send the email!
    mail($your_email_address,$subject,$the_email);
    ?>

    I've not tried any of this code so there may be a few errors and I also cannot guarantee that it is 100% secure. You are almost guaranteed to get spam messages also.

    Hopefully this will point you in the right direction, however


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:32 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com