471,829 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,829 software developers and data experts.

How can I create a Contact form without PHP?

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

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 20019
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>
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. }
  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. ?>
Tell me if the code [edit]doesn't work[/edit], mate.
Feb 17 '11 #3
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
Was that post directed to me, or to OP?
Feb 17 '11 #5
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
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.