469,288 Members | 2,357 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

How can I create a Contact form without PHP?

I want to create a Contact page on my website with the following form boxes:
----------------
Name
e-mail address
Comments

Submit (button)
----------------
I want the customers to send me the comments via email but without prompting for the the local mail client ("mailto:"). Is there a way to write all this in html/css? without applying php? The submit button will send the message right from the browser.

If not, can you help me with the php engine? maybe some advice on how to embed the php code to my ordinary html/css site.

Thank you very much in advance :)
Feb 16 '11 #1
6 19511
drhowarddrfine
7,435 Expert 4TB
I don't even know PHP. PHP does nothing but set up the HTML for the form using form and input elements. Do you know enough HTML to do that?
Feb 16 '11 #2
As far as I know this is not possible. But, if you use this HTML and PHP, it'll be possible:

Your HTML-file (contact.html)
Expand|Select|Wrap|Line Numbers
  1. <form action="mail.php" method="post">
  2. Name: <input type="text" name="name"><br>
  3. E-mai: <input type="text" name="email"><br>
  4. Comment: <br>
  5. <textarea name="comment" cols=50 rows=10></textarea>
  6. </form>
  7.  
Your PHP-file (mail.php):
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function isEmail($email){
  3. if(preg_match("/^(\w+((-\w+)|(\w.\w+))*)\@(\w+((\.|-)\w+)*\.\w+$)/",$email)){
  4. return true;
  5. }
  6. else {
  7. return false;
  8. }
  9. }
  10.  
  11. if( isEmail($_POST['email']) ) {
  12. $name = $_POST['name'];
  13. $email = $_POST['email'];
  14. $comment = $_POST['comment'] . "\r\n\r\n-- \r\n$name";
  15. $datetime = date("Y-m-d H:i:s");
  16. $your_email = 'FILL IN YOUR EMAIL';
  17. $subject = 'Comment from HTML-form: ' . substr($comment, 0, 15) . '...';
  18. }
  19. if( mail ($your_email, $subject, $comment, "From: $email")){
  20. header("Location: contact.html"); //Here, you can replace contact.html with another page that will say "Thank you for your feedback or something like that.
  21. }
  22. else {
  23. echo "Something messed up! I'm sorry! =( <br> Here are the data you sent to this page. Send it to me in an email at $your_email, and I'll answer you. =)<br><br>Name: $name<br>E-mail: $email<br>Comment:<br>$comment";
  24. }
  25. ?>
  26.  
Tell me if the code [edit]doesn't work[/edit], mate.
Feb 17 '11 #3
drhowarddrfine
7,435 Expert 4TB
The only part that needs PHP is handling it on the server side. No language is needed to collect and send the data.
Feb 17 '11 #4
@drhowarddrfine
Was that post directed to me, or to OP?
Feb 17 '11 #5
JKing
1,206 Expert 1GB
I would suggest at the very least validating the email address. Otherwise a user could throw in several email addresses and use your form to spam people.
Feb 17 '11 #6
JKing: That's true. I should have included it, but I forgot.

I'll edit my post and add a function to check that the email is valid. [done]
Feb 17 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Jason | last post: by
18 posts views Thread by Stephanie | last post: by
20 posts views Thread by Steevo | last post: by
6 posts views Thread by skgolden | last post: by
3 posts views Thread by JavaConvert | last post: by
3 posts views Thread by John | last post: by
1 post views Thread by anj | last post: by
reply views Thread by kammaldeep | last post: by
5 posts views Thread by NYXX | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.