Close Panel
 
 

28

Jun

2007

PHP Contact Form Script

By Jeeremie. Posted in Articles, PHP

Here is a nice contact form for your website.

This contact form will return a validation message if the message was sent succesfully.
It will also display an error message if you try to send an empty message or if the e-mail is invalid.

The Demo

SEE THE DEMO »

There are only two scripts for this simple contact form:

  • contact.php : the PHP contact form itself (contact.php)
  • style.css : the CSS page (style.css) to control the layout of the page

Download:

Download (7 KiB, 4,391 hits)

Popularity: 24% [?]

 

Related posts

| Subscribe to Feed | Email the author

23 Responses to “PHP Contact Form Script”

  1. 1
    Adão Braga Says:

    I tested you script.
    http://www.holistica.com.br/artigo1/contato/contact.php

    But my internet provider don´t send the messagen for my inbox. Look, message the CONGRATULATION, but don´t.

    Very Good.

  2. 2
    darlene Says:

    great site for helping people!!…wtg

  3. 3
    Jeeremie Says:

    Hello Adao Braga,

    I tested the contact form you installed on your server but I can’t see what is the problem. Did you changed the email address to be your own in the contact.php page (user@email.com - line 61)? If it is not working, try changing the email to be something else or contact your internet provider. And by the way, check your spam box. It is possible your email provider moved the mail into it.

    I hope it helps you.

  4. 4
    tamara Says:

    is this good for a flash form ?
    my form in flash gives me a message of message sent but i get no emails

  5. 5
    Jeeremie Says:

    Hello Tamara,

    I have no idea. I never tried to adapt it to a flash form but I suppose it is possible.

    However, your problem may due to your e-mail provider. Try to contact them and see if they can first fix it. If not, then it could be a problem with your flash form.

    Let me know.

  6. 6
    Anwar Says:

    Hey, PHP guy!
    I am getting this problem,
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\EasyPHP 2.0b1\www\Shop On!\categories.php on line 68
    I know there is some problem with the mySQL. But EasyPHP is showing it to me as started.
    I have the database in the MYsQL data folder as well. Do you have any idea, what might be the problem ?
    P.S. plz reply on my email adress! Thanks

  7. 7
    shivu Says:

    great site for helping people

  8. 8
    ollie10123 Says:

    Hey, Any plans for expanding the form to include SMTP authenitcation?

    Ollie

  9. 9
    Jeeremie Says:

    No, not at the moment but that’s a good idea Ollie. I will think about it. Thanks!

  10. 10
    Jason Says:

    Hey Jeeremie,

    I know this form is free and so any advice would be greatly appreciated, but understand if you don’t have time to look at it.

    I love this form and am using it a lot but I’ve come across a need for some drop down select menus. Which it works fine and collects the data and emails it, the problem comes in if there is any type of error, the drop-down select menus RESET because there is no way to tell them what the original value was that had been selected by the user.

    I’ve tried several things without success. Thought you might have some advice to make this work. (I sent you an email with the code if you want to look at it).

    Thanks, the site looks AWESOME!!! BTW, FYI, MooFlow works in Firefox 3+ guess I was behind the times =)

    j

  11. 11
    Jeeremie Says:

    Thanks Jason,

    I got your email two days ago but I didn’t have time to look at it yet. I will as soon as possible.

  12. 12
    Jason Says:

    Hey man, no problem, I just appreciate it! Hope things are going great.

  13. 13
    Jeeremie Says:

    Jason,

    Your code was correct. Just replace:

    else if(trim($referred) == '')
    {
    $error = '<div class="errormsg">Please tell us who referred you to us. Thank You!</div>';
    }

    …by:

    else if(trim($referred) == '(Please Select One...)')
    {
    $error = '<div class="errormsg">Please tell us who referred you to us. Thank You!</div>';
    }

    And it should work! you can download the (simplified) code here if you want.

  14. 14
    Jeeremie Says:

    By the way, I will release in a couple of weeks the quote form I used on my old site. It was based on this contact form. Since I am not using it anymore, I think it is a good idea to give it away. I will publish it in approximately one month as I have other posts in the queue waiting to be published.

  15. 15
    Jason Says:

    Hey Jeeremie,

    Thanks for looking at it. I got it to require it so that if it’s not selected it gives an error, but the problem remains that if any error happens, then the select box doesn’t remember what was selected and reset itself back to the default… does that make sense?

    Sorry if I was not more clear. I really appreciate your time.

  16. 16
    Jeeremie Says:

    I tried this and it works! Check it by yourself (click on [+] to expand the code) :

  17. 17
    Jeeremie Says:

    By the way, if you want to validate a phone number in your PHP contact form, add this code:

    else if(trim($phone) == '')
    {
      $error = '<div class="errormsg">Please enter your phone number!</div>';
    }
    else if(!preg_match("/^[0-9]{6,}$/",$phone))
    {
      $error = '<div class="errormsg">Please enter a valid phone number!</div>';
    }

    … like this: (click on [+] to expand the code)

    The code “/^[0-9]{6,}$/” will check if the phone number contains only numbers ([0-9]) and if the number contains at least 6 characters ({6,}). You can increase this number if you want. For example, in Spain, phone numbers contains at least 9 numbers. Your code could be: “/^[0-9]{9,}$/”.

  18. 18
    Jason Says:

    DUDE, did you re-write the entire form?? OH MY GOODNESS!!! I’m so so sorry. I just thought it might be a quick fix. I did not mean for you to have to do all that work.

    Nevertheless it works AWESOME!!!! Perfect. You should upload it as a download as a NEW form with your other two because it’s completely different in a lot of ways =)

    THANKS!!!!!!!!!!

  19. 19
    Jeeremie Says:

    You are welcome Jason. I enjoyed it anyway!

  20. 20
    mohd saif Says:

    hi,
    the problem statement for comment number 6 of anwar is:
    please check your connection variable and the database variables in the mysql_connect and mysql_select_db.

  21. 21
    Navin Says:

    Hi Jeeremie,

    what a piece of simple php script, its a best one i came across.

    Can you please tell me how can i add drop down box to your wonderful script which should include in mail

    dropdown1 : Date
    dropdown2 : month
    dropdown3 : year

    please help me its important to me.

  22. 22
    Obzolete Says:

    I just get this errormessage:

    The POST method has been disabled by the server administrator

  23. 23
    Jeeremie Says:

    Maybe your host does not allow to send messages with the post method. Contact your host and ask them.

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

To insert a code, don't use <code>...</code>. Instead, use <pre lang="LANGUAGE" colla="-">...</pre> and replace 'LANGUAGE' by 'html4strict' for HTML, 'php', 'javascript', 'css'...