main topics archive podcast connect
about 12 years ago
SGP has no shortage of cases for iPhone or iPad, and their Linear Mini series, while being their budget line, is far from being comparable to a generic means of protection ...
about 13 years ago
This week we talk some pretty important stuff like Anime Expo 2011, Captain America (is it good, bad, ugly?), MacBook Battery hacking, 3DS price cuts (now just $169), Battlefield 3 Alpha ...
about 13 years ago
This week, we have a special show because we’re giving away a copy of the new Annihilation DLC for Call of Duty Black Ops (Steam, PC). We’ve done Giveaways before, but ...
about 13 years ago
On this week’s show, Connor and Brandon talk Facebook Video chat, cereal and milk, Bioshock Infinite, Quadrotors, the new Youtube, Spotify coming to the US, Connor gets his iPhone hacked and ...
about 13 years ago
Special thanks — to Connor for filling in this episode!!! On this installment of the Okay Geek Show, Ricardo is away at the 2011 Anime Expo spreading the joy of Okay Geek with ...
about 13 years ago
  We have been underground bashing our keyboards and inhaling coffee for the past two weeks covering E3 2011 which has been a blast, but a lot of hard work. ...
about 13 years ago
  This week on the show, Ricardo and Brandon sit down and talk about the widest veryity of topics ever discussed before… we start with Basketball and end up talking ...
about 13 years ago
  This is our first video podcast, and we’re so proud we managed to do it live on Friday, all in one take. This episode, Ricardo and Brandon start the ...
about 13 years ago
  This week, we are talking about a veryity of topics that are strange, just as they are awesome. We’re talkin’ Bear Grylls, Piss, Thor, vocaloid raves, and a bunch ...
about 13 years ago
  You remember the our old podcast right? Well that was somewhat of a test. A test to see if our readers would enjoy hearing us and listening to what ...
  • Have a suggestion?

  • *
  • *
  • *

REQUIRED READING

Notify Ricardo

When you finish something, notify Ricardo (Executive Editor) via a private DM through Twitter.

Okay Geek Traffic Traffic live stats Twitter activity Facebook Page Image compress app Tips & Guidelines Report a problem
← Previous Clean slate Next →
Friday
Jun172011

How to easily create a simple PHP Email Form

If <form action=”mailto: example@me.com”> simply isn’t cutting it anymore, it might be time to implement a PHP form, and from a design and usability perspective, users would much rather send a message directly from your website than their email client (most of us don’t even use an email client). Plus, if you have no prior experience with PHP, we break everything down for you. Let’s get coding!

Step 1 - The HTML

<form method=”post” action=”contact.php”>Email Address: <input name=”email” type=”text”><br> Message:<br> <textarea name=”message” rows=”5” cols=”60”></textarea><br> <input type=”submit”> </form> 

If you’re familiar with HTML forms, you’ll recognize the form action and input types. What you probably have never seen before is form method=”post”. When a visitor clicks submit, this collects the user’s email address and message. It is then passed through “contact.php” where it’s sent to your predefined email. You with me so far?

Step 2 - The PHP

 <?php $to = “example@me.com”; $subject = “New Message”; $email = $_REQUEST[‘email’] ; $message = $_REQUEST[‘message’] ; $headers = “From: $email”; $sent = mail($to, $subject, $name, $message, $headers) ; if($sent) {print “Thanks for your message. We’ll get back to you soon.”; } else {print “Hold the phone! There seems to be a problem sending your message.”; } ?> 

This PHP file simply defines the email address where all submissions should be sent. In an effort to go a little further, it formats the email for you. Let’s break this down further. When a user submits a message, $_REQUEST grabs the data entered into the form moments earlier. Then, the message is formatted into something you and your email client will be able to understand. If sent correctly, a message of sucess will appear. If something went wrong, a message of failure will appear.

Step 3 - Getting it Working

Now that you have an understanding about what the code does, let’s get it working. The PHP code should be saved in a seperate file called, “contact.php”. You’ll then want to upload it to your website and copy down the location of the it on your server. 

IMPORTANT: In order for your contact form to function correctly, your hosting service must support PHP on their servers. Also, if you forget to save with the .php file extension, your form will be useless. 

After you have your PHP file uploaded, open your HTML file and replace “contact.php” with the location of the PHP file on your server. Save it as an HTML document and then upload. Finally, test it to make sure it works properly. Congratulations, if you’ve followed these instructions correctly, you have a new PHP contact form for your website.

Discussion Threads

Follow and Subscribe to Okay Geek - We always send our latest articles to Twitter, RSS, Facebook and more, as well as other awesome content we find interesting.

Related Posts Plugin for WordPress, Blogger...