PDA

View Full Version : [PHP] Email Contact form


cillian
04-04-2009, 12:08 AM
Just a simple Email contact form coded in PHP, This is aimed more towards people who know HTML.

Tomorrow I will make one with a HTML site, but not now as its 1:05 am =p

Anyway just save this as a php file and upload it etc.

<?php

/* Subject & Email Variables */

$emailSubject = 'Insert Subject Here';
$webMaster = 'youemail@domain.com';

/* Data Gathering Variables */

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$commentField = $_POST['comment'];

/* You can add more fields like above for by copying and pasting another. and editing the $_POST and $<NAME>Field */

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Comment: $comment <br>
EOD;

$headers = "From: $email\r\n";
$headers = "Content-type: text/html\r\n";
$success = Mail($webMaster, $emailSubject, $body, $headers");

/* Insert HTML between EOD tags for what to show person */

$results = <<<EOD
Thank you for you Email
EOD;
echo "$results";


?>

Double
04-04-2009, 12:24 AM
this is useful. +rep
this can be used for reporting bugs to server admins, plus, applications. for the server owners who dont want forum spammed with "my app" posts lol

cillian
04-04-2009, 01:48 AM
Yep exactly, and with the comment stating where, they can add more fields for apps =p

Thanks for the rep.

Xile
04-04-2009, 01:47 PM
Bump

cillian
04-04-2009, 02:56 PM
Will start working on a webpage version with all the HTML ready.

And then I will start working on a Full Website during the week.

jamie
04-04-2009, 07:32 PM
bump

Ubbelol
04-04-2009, 07:47 PM
Epic cillian! +rep
And +<3 to Jamie

cillian
04-04-2009, 07:49 PM
Thanks mattias <3

Ubbelol
04-04-2009, 07:51 PM
Thanks mattias <3

Oh meh gawd! You are like the first on saying my real name on Ac-Web =)
You'll get a reward in some way, some day, somewhere. When you least expect it. ^^

cillian
04-04-2009, 07:52 PM
Translation:

You will have 1337 buttsecks tonight ^^

Ubbelol
04-04-2009, 07:53 PM
Translation:

You will have 1337 buttsecks tonight ^^

Pretty much, yea. xD

cillian
04-04-2009, 07:54 PM
Yay! :D

judgedread88
04-13-2009, 01:04 AM
It really isn't hard to convert to HTML. Hope you do Cillian!

cillian
04-13-2009, 01:07 AM
Yeah I'll do it when I'm back home and have my PC. :)

ProphetX
04-13-2009, 01:39 AM
Nice release, Cillian. Many people will find this useful :)

People may also want to change the headers so that they know the email is from the contact form, for example:
$headers = "From: Your Website Email Notification" . "\r\n" .
"Reply-To: $nameField <$emailField>" . "\r\n";
mail($webMaster, $emailSubject, $body, $headers);

And to prevent unauthorised execution of this script you may want to make sure that the form has actually been submitted, so in your HTML page you have:
<input type="submit" name="submitContactForm" value="Send Email" />

and in the PHP file at the top:
$submit = $_POST['submitContactForm'];

if (isset($submit)) {
...Rest of the code...
}

cillian
04-13-2009, 12:02 PM
Nice release, Cillian. Many people will find this useful :)

People may also want to change the headers so that they know the email is from the contact form, for example:
$headers = "From: Your Website Email Notification" . "\r\n" .
"Reply-To: $nameField <$emailField>" . "\r\n";
mail($webMaster, $emailSubject, $body, $headers);

And to prevent unauthorised execution of this script you may want to make sure that the form has actually been submitted, so in your HTML page you have:
<input type="submit" name="submitContactForm" value="Send Email" />

and in the PHP file at the top:
$submit = $_POST['submitContactForm'];

if (isset($submit)) {
...Rest of the code...
}

Thanks Prophet.

not the best at PHP yet =p - Just started learning really =p