Sinisterly
Simple contact form - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: PHP (https://sinister.ly/Forum-PHP)
+--- Thread: Simple contact form (/Thread-Simple-contact-form)



Simple contact form - Slim - 05-13-2013

Here is a tutorial I threw together quickly on how to code a simple PHP contact form for your website - thought it would be useful since most websites contain something like this.

contact.html
Code:
<form method="POST" action="process.php"> <input type="text" name="name" size="19" placeholder="Name"><br> <br> <input type="text" name="email" size="19" placeholder="Email"><br> <br> <textarea rows="9" name="message" cols="30" placeholder="Message"></textarea> <br> <br> <input type="submit" value="Submit" name="submit"> </form>

process.php
Code:
<?php if(isset($_POST['submit'])) { $to = "slim@thug.pw"; // your email for receiving submissions $subject = "You have a new submission"; // subject of the emails sent to you $name_field = $_POST['name']; // process name $email_field = $_POST['email']; // process email $message = $_POST['message']; // process message $body = "<strong>From:<strong> $name_field\n <strong>E-Mail:</strong> $email_field\n <strong>Message:<strong>\n $message"; // message format as it will be sent to you echo "Thank you for your submission! "; // success message mail($to, $subject, $body); } else { echo "There was an error, please try again!"; // error message } ?>

There you go, a fully-functional PHP contact form. Now you can go back and style the contact.html page to your liking.


RE: Simple contact form - Combo - 05-14-2013

Pretty useful indeed, thank you for sharing. I'm interested in advancing far in PHP to be honest. Smile


RE: Simple contact form - Slim - 05-15-2013

(05-14-2013, 02:55 PM)Combo Wrote: Pretty useful indeed, thank you for sharing. I'm interested in advancing far in PHP to be honest. Smile

Awesome, need any help then I am your guy. Even request some tutorials, if you wanted.


RE: Simple contact form - Banadmin - 05-19-2013

Thanks, Geo for this tutorial. Smile


RE: Simple contact form - LessThan3 - 05-20-2013

Sweet tutorial, one I had been working on didnt work :\

Thanks!


RE: Simple contact form - Banadmin - 05-22-2013

Just tried this on my localhost and I'm now working on the CSS sides of things. Works like a charm. Biggrin


RE: Simple contact form - Krew - 05-22-2013

Thank you very much. Using this as a contact form on my websites that are for sale =)


RE: Simple contact form - Slim - 05-22-2013

Always love to see people using my tutorials, even better if you learn something from it. Any suggestions for more stuff?