1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP Any free PHP contact form?

Discussion in 'Web Development' started by flek, Jan 9, 2010.

  1. Jiggles

    Jiggles Member

    Correct :)
     
  2. dunkoo

    dunkoo New Member

    oh! Your reply is fast! Anyway, do you mind that I attach my work file overhere and you help me take a look of it? cause I follow as what you said and looks like its even worst than the previous one. So sorry to trouble you.
     

    Attached Files:

  3. Jiggles

    Jiggles Member

    Remove all files appart from the contact.php file and remove the recaptchalib.php file from the folder and have them in the same folder as each other. This is all you need. It should work then. :)
     
  4. inljeyaraman

    inljeyaraman New Member

    php is really deals with SEO

    Regards
    inljeyaraman
     
  5. L York

    L York New Member

    Hoping to get some help on this. Using this php script in my website I find that the From: and the Subject: are the same when I get the email response from the form. How can I set a static Subject: message, and not have it be a variable taken from the form? This is driving me crazy as I've tried setting this in the form for the past two days trying different coding and nothing works. E.g., I want the specific Subject: of "New addition to the mailing list." to appear each time a message is received in response to the form.
     
  6. Recidivist

    Recidivist VIP Member

    The short answer:

    This must be done in the PHP not the HTML.
    Change:

    PHP:
    //Email Subject
    $subject $_POST['subject'];
    To:

    PHP:
    //Email Subject
    $subject "I am a static subject";

    Longer answer:


    I don't know how familiar you are with PHP or programming in general, but perhaps a little context might help.

    You can assign a value to name and refer to the value using only the name. These are called 'variables'. They are defined differently in different languages, but PHP defines them "$variable". Anything with a $ behind it in PHP is a reference to a variable. To set a variable, you simple say that the variables equals a value.

    eg

    PHP:
    $string "I am some text";
    $integer 123;
    $boolean false;
    You can call variables (almost) anything. At the most basic, they can be made of strings (lines of text), integers (numbers), booleans (true/false). Variables can reference a lot more in various languages, but those are probably the three main types.

    To get the value of the variable, you simply use the variable. You assign a variable by referring to another variable.

    Eg

    PHP:
    $v1 123;
    $v2 $v1;
    We set $v1 to 123, then set $v2 to the value of $v1. So $v2 is now 123, It would be the same as saying $v2 = 123.

    Importantly, PHP has functions which represent blocks of code that you can reuse anywhere else in your code. Functions can take parameters, which are just a set of values that the function uses inside it's block of code. To call a function, it looks like this:

    PHP:
    function_name();
    function_name("string");
    function_name(123);
    function_name(false);
    function_name(false123);
    function_name("string""string"123falsetrue"string");
    You can tell a function call by a name followed by some parenthesis. The parameters are contained in the parenthesis. You can pass as many parameters as the function expects (functions expect a set amount of parameters is most cases, 0 or more).

    You can use variables and functions together, and you get something like this:

    PHP:
    function_name($variable);
    Now if earlier in the code we say:

    PHP:
    $variable "string";
    Then that call to the function is the same as if we had just written "string" inside the parenthesis.

    Now, if we go back to your problem.

    The $subject variables is defined at the top and set to $_POST['subject']. I won't go into specifics, but this is getting a value from your HTML form and assigning it to the variable $subject.

    The variable $subject is then used in the function call to send the email here:

    PHP:
    //Email the script
    $send_email mail($to_email,$subject,$message,$header);
    By changing the value you assign to $subject to whatever you want the subject to be, you pass that value to the email here.

    And just for clarity, this would be the same as doing:

    PHP:
    //Email the script
    $send_email mail($to_email,"I am the email subject",$message,$header);
    But it should be obvious that this way is not very neat or readable. If you look at the code in a months time, will you remember that you put the subject there?

    Always give your variables sensible names. Try to keep them short, but sensible.

    Lines should always end with a semi-colon " ; ". This marks the end of a statement and without it you will run into all sorts of errors.


    Hope this helps, sorry if anything is unclear, just got off a flight and absolutely shattered.
     
    Last edited: Sep 20, 2014
    ishkey likes this.
  7. L York

    L York New Member


    Thanks for the detail. No, I'm not familiar at all with PHP. It appears my main problem was in not understanding the way the way the various fields in an email are interpreted. Meaning, I had changed some of the variable names to suit the custom form I was making, but didn't change those same variables in the "script" line (essentially your last screen grab insertion). So, thanks again.
     
  8. Recidivist

    Recidivist VIP Member

    No problem. I hope your issue is resolved, if you need anything else just make a thread or send a PM and we'll sort you out.

    Have a great day!
     
  9. katende

    katende New Member

    thnx let me try these codes first and see
     
  10. youronline va

    youronline va New Member

    Try this, a spam-less contact form that'll let you send the reply emails to 2 different email recieving addresses. I use this exclusively anytime I need a contact form or I do a videosqueeze page and want to hook the form up to my admin addy and auto responder;
     
  11. Bruce Kenway

    Bruce Kenway New Member

    With this script in a PHP file contact.php, then try to upload it to a PHP enabled server. This form only uses the one page and would fix the issue
     
    parthdudhagra likes this.
  12. 3D Power

    3D Power New Member

    Last edited by a moderator: Nov 7, 2015
    parthdudhagra likes this.
  13. parthdudhagra

    parthdudhagra New Member

    File Name: send_form_email.php

    Mail Form(Contact Form) php Code Screenshot
    Email Form php Code Input - Click here
    Email From Output - Click here
     
  14. Hello Dear

    - PHP Contact Form -

    Input -


    <?php
    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "you@yourdomain.com";
    $email_subject = "Your email subject line";


    function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    }
    $string_exp = "/^[A-Za-z .'-]+$/";
    if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
    }
    if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
    }
    if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
    }
    if(strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";


    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    <!-- include your own success html here -->
    Thank you for contacting us. We will be in touch with you very soon.
    <?php
    }
    ?>

    - Output -


    [​IMG]