Welcome To Freeware Tips Forum Index
Join! (free) SearchFAQMemberlistUsergroupsLog in

Basic PHP Email Forum

 
Reply to topic    Welcome To Freeware Tips Forum Index » Coding Tips -> PHP View previous topic
View next topic
Basic PHP Email Forum
Author Message
Please Register and Login to this forum to stop seeing this advertsing.




Speed
Site Admin

Joined: 16 Jul 2008
Posts: 1247
Add Comment
Show Comments
Add Karma



Post Basic PHP Email Forum Reply with quote
Below is a simple cut and paste solution for a Basic PHP E-mail form with form validation that will e-mail you from your web site. After submission it will confirm that the email has been sent.

Create a PHP file called mail.php or whatever you like (make sure the file extension is .php e.g. anything.php). Cut and paste the code below in the PHP file. This file contains the form and PHP code that validates and emails the form.

(customize the parts in CAPS to reflect your own information):


Code:
<!-- Cut code below this line -->

<?php

// Change below to the email address where you want to receive the message.
// (inside the quote marks 'receive@yourdomain.com'')
$myemail = 'RECEIVE@YOURDOMAIN.COM';

// Change this to the subject of your message.
// (inside the quote marks 'PHP Mail Form Subject'')
$subject = 'PHP MAIL FORUM SUBJECT';

$op = $_POST[op];

if($op == 'contact')
{
$name = stripslashes($_POST[name]);
$email = stripslashes($_POST[email]);
$text = stripslashes($_POST[text]);

if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email))
{
$status = "We're sorry, but you've entered an incorrect email address.<br>";
}
if(!$name)
{
$status .= "Please enter your name.<br>";
}
if(!$text)
{
$status .= "Please enter a message.<br>";
}

if(!$status)
{
$header = "From: $email\r\nReply-To: $email\r\n";

$message = "
Name: $name
Email: $email
Message: $text
";

if(mail($myemail, $subject, $message, $header))
{
$status = "Thank you for your Feedback!!<br><br>";
}
else
{
$status = "There was a problem sending your feedback, please try again later.<br><br>";
}

}
else
{
$status .= "<br>Please press <u>back</u> on your browser to resubmit.<br><br>";
}
}

// Now check the referer page and ensure it's a proper URL

$referer = $_SERVER[HTTP_REFERER];

if(!preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $referer))
{
unset($referer);
}

?>

<?php print $status; ?>

<form method="post" action="<?php print $_SELF; ?>">
<input type="hidden" name="op" value="contact">
Name:<br>
<input name="name" size="35" value=""><br>
E-mail address:<br>
<input name="email" size="35" value=""><br>
<br>
Message:<br>
<textarea name="text" cols="50" rows="10"></textarea><br><br>
<input type="submit" value="Send message!">

<!-- Cut code above this line -->


That's it!

Your Friend,





~Speed

_________________


Train Insane or Remain The Same
There's No Room In A Warriors Heart For Self Doubt

Last edited by Speed on Sat Jan 10, 2009 1:55 am; edited 1 time in total
Sun Oct 26, 2008 8:55 pm View user's profile Send private message Visit poster's website
Josh
Co Admin

Joined: 16 Jul 2008
Posts: 110
Add Comment
Show Comments
Add Karma



Post Reply with quote
I have that one on mine
Mon Oct 27, 2008 7:24 am View user's profile Send private message Visit poster's website
Speed
Site Admin

Joined: 16 Jul 2008
Posts: 1247
Add Comment
Show Comments
Add Karma



Post Reply with quote
thumbright




_________________


Train Insane or Remain The Same
There's No Room In A Warriors Heart For Self Doubt
Mon Oct 27, 2008 9:01 am View user's profile Send private message Visit poster's website
Display posts from previous:    
Reply to topic    Welcome To Freeware Tips Forum Index » Coding Tips -> PHP All times are GMT
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Design by Speed