Skip to content

Commit 51ea849

Browse files
committed
This is the beginning. The first commit. Let's see what happens.
0 parents  commit 51ea849

File tree

6 files changed

+468
-0
lines changed

6 files changed

+468
-0
lines changed

config.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
//This is the only required setting. Replace the email address below
3+
//with the email address you'd like to receive the forms at.
4+
$sendToEmail = '[email protected]';
5+
6+
//------------EVERYTHING BELOW THIS POINT IS OPTIONAL---------------
7+
8+
//This is the name of the file to use when no template is passed.
9+
$templateFile = 'template.txt'; //Default is template.txt
10+
11+
//This is the default page that should show after the information is submitted.
12+
$redirectDestination = NULL; //Default is NULL
13+
14+
//This tells the script wether you want to use reCAPTCHA or not
15+
$recaptchaEnabled = TRUE;
16+
17+
//If you have your own recaptcha pub/priv key enter it here.
18+
//You CAN use the keys provided, but keep in mind they are publicly known.
19+
//
20+
//Default values:
21+
//$recaptchaPubKey = "6LfGEwsAAAAAAEfdb77X7r7gbSJwOlLz44-RW6zA";
22+
//$recaptchaPrivKey = "6LfGEwsAAAAAALlZSbCjaZpUdPhce7w03BAfQMpp";
23+
24+
$recaptchaPubKey = "6LfGEwsAAAAAAEfdb77X7r7gbSJwOlLz44-RW6zA";
25+
$recaptchaPrivKey = "6LfGEwsAAAAAALlZSbCjaZpUdPhce7w03BAfQMpp";
26+
27+
//This is passed as the 5th paramter to the mail function. You can use
28+
//this to specify special paramaters to be used in the sendmail command.
29+
30+
$sendmailParam = "-ODeliveryMode=b";
31+
32+
?>

docs/howto.rst

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Introduction
2+
============
3+
4+
This script is designed to allow someone with little knowledge of scripting,
5+
but some knowledge of html to create an email "contact" form. When designing
6+
this script, I had 2 major goals.
7+
8+
1. Little-to-no configuration.
9+
------------------------------
10+
11+
The only necessary configuration in the script is to set your email
12+
address you would like to receive the emails at. There are other
13+
configuration options if you would like to have extra features (like a
14+
redirect page or captcha spam protection) but you CAN just create an
15+
email template and point a form action to the script and it will send
16+
you emails.
17+
18+
2. Compatability
19+
----------------
20+
21+
I wanted this script to be compatible with as many servers as possible
22+
with out having to make any server side settings. This is why I wrote
23+
it in php, instead of python. With most hosts, you will already have
24+
php and sendmail installed, configured and ready to go.
25+
26+
The basic setup
27+
===============
28+
29+
With the most basic setup, you get a script that accepts a form action by the
30+
POST method and then send the information using a template you create to form
31+
the email data how you would like it.
32+
33+
Building the form html
34+
----------------------
35+
36+
In order to have a form on your site, you must add the form to one of your html
37+
pages. This can be done just by editing the html page with a text editor, or
38+
by most webbuilding softwares by adding the form fields. If you use a site
39+
building software, you may still need to edit the html code by hand, so I'll
40+
breifly go over the html tags used to build the form and what they do.
41+
42+
There are 2 basic html tags used when building a form.
43+
44+
1. <form></form> tag
45+
~~~~~~~~~~~~~~~~~~~~
46+
47+
All <input> tags (we'll talk about those next) must go between the <form> and
48+
</form> tags in your html code. The <form> tag also contains some info

form.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<head>
2+
<title>This is my title</title>
3+
</head>
4+
<body>
5+
This form is for testing out my templating for my mail script. It's an addlib of one of my sister's fan fics she wrote. Feel free to fill it out and it will send the addlib to me. <br>
6+
<br>
7+
Please put everything in past tense unless otherwise stated.<br>
8+
<br>
9+
<form action='process.php' method='post'>
10+
adjective <input type="text" name="adjective1"><br>
11+
adjective <input type="text" name="adjective2"><br>
12+
animal<input type="text" name="animal1"><br>
13+
verb<input type="text" name="verb"><br>
14+
adjective<input type="text" name="adjective3"><br>
15+
animal<input type="text" name="animal2"><br>
16+
17+
<script type="text/javascript"
18+
src="http://api.recaptcha.net/challenge?k=6LfGEwsAAAAAAEfdb77X7r7gbSJwOlLz44-RW6zA">
19+
</script>
20+
<noscript>
21+
<iframe src="http://api.recaptcha.net/noscript?k=6LfGEwsAAAAAAEfdb77X7r7gbSJwOlLz44-RW6zA"
22+
height="300" width="500" frameborder="0"></iframe><br>
23+
24+
</noscript>
25+
26+
27+
<input type='submit' name='Click here to email me the adlib!'>
28+
</form>
29+
</body>

process.php

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
require_once('config.php');
4+
5+
6+
if($recaptchaEnabled)
7+
{
8+
if(!isset($_POST["recaptcha_challenge_field"])
9+
|| !isset($_POST["recaptcha_response_field"]))
10+
{
11+
die("Invalid CAPTCHA verification. Please go back and try again.");
12+
}
13+
require_once('recaptchalib.php');
14+
15+
$resp = recaptcha_check_answer($recaptchaPrivKey,
16+
$_SERVER["REMOTE_ADDR"],
17+
$_POST["recaptcha_challenge_field"],
18+
$_POST["recaptcha_response_field"]);
19+
20+
if(!$resp->is_valid)
21+
{
22+
die("Invalid CAPTCHA verification. Please go back and try again.");
23+
}
24+
}
25+
if(isset($_POST["template"]))
26+
{
27+
$template = file($_POST["template"]);
28+
}
29+
else
30+
{
31+
$template = file($templateFile);
32+
}
33+
34+
$emailBody = "";
35+
$subject = "";
36+
37+
if(isset($_POST["email"]))
38+
{
39+
$subject = "Contact form message from ".$_POST["email"];
40+
}
41+
else
42+
{
43+
$subject = "Contact form message.";
44+
}
45+
46+
$pattern = "/\{([a-zA-Z0-9_]+)\}/i";
47+
48+
foreach($template as $line)
49+
{
50+
$emailBody .= preg_replace_callback(
51+
$pattern, create_function(
52+
'$matches',
53+
'$temp = trim($matches[0], "{}");'.
54+
'if(isset($_POST[$temp])){'.
55+
'return $_POST[$temp];}'.
56+
'echo $_POST[$temp]; return "{NOT SPECIFIED}";'),
57+
$line);
58+
}
59+
60+
if(isset($_POST["redirectURL"]))
61+
{
62+
$redirectDestination = $_POST["redirectURL"];
63+
}
64+
65+
if(@mail($sendToEmail, $subject, $emailBody, NULL, $sendmailParam))
66+
{
67+
if(isset($redirectDestination))
68+
{
69+
header("Location: $redirectDestination");
70+
}
71+
else
72+
{
73+
echo "Thank You for using John's form processing script. Your message has delivered successfuly.";
74+
}
75+
}
76+
else
77+
{
78+
echo "An error prevented your message from sending. Please try again later.";
79+
}
80+
?>

0 commit comments

Comments
 (0)