|
|
|
|
Thread title: PHP Contact Script |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
12-10-2006, 09:04 PM
|
#1
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
PHP Contact Script
Hey, just made this for one of my sites, so I thought I'd let you guys use it.
PHP Code:
<?php
if (isset($_POST['submit'])) {
// Just make all the info good to work with
$to = "admin@example.com";
$subject = "Example.com Contact Form";
$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$message = trim(stripslashes($_POST['message']));
$reason = ucfirst($_POST['reason']);
// Check all fields for values
$error = false;
if (trim($name) == "")
$error = true;
if (trim($email) == "")
$error = true;
if (trim($message) == "")
$error = true;
if ($error == true) {
echo "<span class=\"error\">One of the fields has been left blank. Please fill out all fields and try again.</span>\n";
} else {
// Make the email all pretty
$body = "Name: ".$name."\n";
$body .= "Email: ".$email."\n";
$body .= "Reason for Contact: ".$reason."\n";
$body .= "Message:\n".$message;
// Headers (thank you Patrick Paul)
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: ".$email."\n";
// Send Email
$sent = mail($to, $subject, $body, $headers);
// Print results
if ($sent) {
echo "<p>Your email has been sent. Please allow time for a reply.</p>\n";
} else {
echo "<span class=\"error\">There has been an error while trying to send your email. Manually send an email to the webmaster to have this problem corrected.</span>\n";
}
}
}
?>
Code:
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<p>Name:</p>
<input type="text" name="name" />
<p>Email:</p>
<input type="text" name="email" />
<p>Reason for contact:</p>
<select name="reason">
<option name="1" value="support">Support</option>
<option name="2" value="feedback">Feedback</option>
<option name="3" value="feature request">Feature Request</option>
</select>
<p>Message:</p>
<textarea name="message" rows="6" cols="40"></textarea>
<p><input type="submit" name="submit" value="Submit Form" /></p>
</form>
|
|
12-10-2006, 09:09 PM
|
#2
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
thanks for the share, possible to add a file to send with the email?
-Alex.
|
|
12-10-2006, 09:10 PM
|
#3
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
Eh, I'm too lazy..
|
|
12-10-2006, 09:16 PM
|
#4
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
ok, guess ill go goggle it :P
Thanks for whats there so far.
Alex.
|
|
12-10-2006, 09:31 PM
|
#5
|
Status: Sin Binner
Join date: Nov 2006
Location: England - Leeds
Expertise:
Software:
Posts: 476
|
Danke
|
|
12-10-2006, 09:52 PM
|
#6
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
Originally Posted by Vlux
Danke
|
Dankechen actually :P
I think :S
|
|
12-13-2006, 07:31 AM
|
#7
|
Status: I love this place
Join date: Aug 2006
Location: Wenatchee, Washington
Expertise:
Software:
Posts: 662
|
Originally Posted by halotree06
Dankechen actually :P
I think :S
|
no. just.... no.
Danke = Thank you
Danke Shön = Thank you very much
and im not even German haha
|
|
12-13-2006, 11:31 AM
|
#8
|
Status: Member
Join date: Nov 2006
Location: Nowhere
Expertise:
Software:
Posts: 192
|
I got another one here if anyone's interested.
PHP Code:
<?php
/*
Written by sparckyz
*/
//get variables
if($_POST['from'] && $_POST['sub'] && $_POST['mess'])
{
//your e-mail address
$To="some@address.com";
//check recipients e-mail address is formatted correctly
if(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$To))
die("please enter a valid 'to' address.");
//check senders e-mail address is formatted correctly
if(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$_POST['from']))
die("please enter a valid 'from' address");
//simplify variables
$From=$_POST['from'];
$Subject=$_POST['sub'];
$Message=$_POST['mess'];
//mail the message
$Mail=mail($To,$Subject,$Message,"from: $From");
//check if message was sent
if($Mail)
{
echo "message sent successfully.";
}
else
{
echo "unable to deliver message.";
}
}
?>
<!-- html form -->
<form name="mail" method="post" action="<?=$php_self ?>">
from:<br> <input type="text" name="from"><br>
subject:<br> <input type="text" name="sub"><br>
message:<br> <textarea name="mess" wrap="virtual" cols="30" rows="4"></textarea><br>
<input name="mail" type="submit" value="mail">
</form>
I wrote it a few days ago out of boredom, so might as well post it
|
|
12-13-2006, 06:15 PM
|
#9
|
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
Posts: 1,132
|
Originally Posted by WardLarson
no. just.... no.
Danke = Thank you
Danke Shön = Thank you very much
and im not even German haha
|
and im taking GCSE next year.
Ich muB lerne Deutsch! aber ich habe viel zu machen!
*admits defeat* :P
Alex.
|
|
12-13-2006, 06:20 PM
|
#10
|
Status: Member
Join date: Nov 2006
Location: Nowhere
Expertise:
Software:
Posts: 192
|
patrickPaul, your clearly more of an elite coder than i am. So i bow down to your logic
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|