• Log in or sign up for an account here: https://www.sythe.org/login

[PHP] Simple 'contact' form

Banned
Joined
Apr 9, 2007
Sythe Gold
5
Messages
1,563
Age
35
Location
Illinois, USA.
[PHP] Simple 'contact' form
This is a really simple contact form designed to be put on your website so a user can contact you easily.

You'll need to create 2 files; and .html and a .php file named contactform.html and ************, respectively.

Use the following HTML code in your .html file:
Code:
<form method="POST" action="************">
   <p>Your Name:<br>
     <input type="text" name="name" size="19" />
     <br />
     Your Email Address:<br>
     <input type="text" name="email" size="19">
  </p>
   <p>
     <select  size="1"  name="subject" id="subject">
<option>Business</option>
<option>Site Issue</option>
<option>Personal</option>
<option>Other</option>
</select>
     <br />
    <br>
      Message:<br>
       <textarea rows="9" name="message" cols="30"></textarea>
      <br>
      <br>
      <input type="submit" value="Submit" name="submit">
      </p>
</form>

and use the following PHP code in your ************ file:
PHP:
<?php

if(isset($_POST['submit'])) {

//Change "YOUR_EMAIL_ADDRESS" to the email you want the messages ent to.
$to = "YOUR_EMAIL_ADDRESS";
$subject = $_POST['subject'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Message sent to $to";
mail($to, $subject, $body);

} else {

echo "Email not sent, try again.";

}
?>

A couple notes:
- be sure to change the Value of the $to variable to your email address you want the script to send the emails to.
- You can add/remove/change the drop down options of the subject by editing the HTML.

Edit:
I forgot to mention, you host must have the "SendMail" function set in the php.ini file, or this won't work.

Edit2:
Errr, the "************" above should be contact [dot] php, I'm not sure why it filtered this.
 
Runescape Gamblingrunescape gambling
Back
Top