This is a ready to go PHP script that can be pasted into a blank .php document. Run it through your webserver after changing $myemail to the value of your E-Mail address. It also sends the referring URL to help you know where the visitor was before he clicked to contact you.
<?php
// Change these two variables to meet your needs.
$myemail = 'myemail@domain.com';
$subject = 'Contact form Subject';
$op = $_POST[op];
if($op == 'contact')
{
$name = stripslashes($_POST[name]);
$email = stripslashes($_POST[email]);
$text = stripslashes($_POST[text]);
$referer = $_POST[referer];
$remote_host = $_SERVER[REMOTE_ADDR];
$server = $_SERVER[SERVER_NAME];
$browser = $_SERVER[HTTP_USER_AGENT];
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",$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
Referer: $referer
Site: $server
Remote Host: $remote_host
Remote Browser: $browser
$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">
<input type="hidden" name="referer" value="<?php print $referer; ?>">
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!">
</form>
i've found the solution here...
http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php
Sorry for the disturb...
Deprecated: Function eregi() is deprecated in /directory/directory/directory/directory/directory/directory/filename.php on line 33
It seems that the function eregi() doesn't work with PHP 5.3
Any ideas?
if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,4})$",$email))
{
$status = "We're sorry, but you've entered an incorrect email address.
";
}
i just creatig a website in free domain,because then i will be ready with my site,then i done this my web,i will upload in normal domain..now my hosting is byethost..maybe u are right..but can somehow this my email hide in source? or do u know maybe how hide all source? sorry for english,i hope u understand me :)
Thank you for your patients, Hawkee. This is what I see on my email:
Name: test
Referer:
Site: www.tranquilimages.com
Remote Host: 76.88.229.88
Remote Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17
testing
As you could see, I am not able to reply to the sender. Most of the time I would like to thank them for their feedback but are unable to. If you still have the patients to help me I would appreciate it very much.
Hawkee, thank you very much for your reply. I am a novice at coding therefore need a little more help. I copied and pasted the script onto my contact form and only changed 'myemail@domain.com' to 'info@tranquilimages.com'. I left the ' marks in. Should I have changed anything else. Where is my "field name"? Thank you for your patients. You could look at my feed back form at http://www.tranquilimages.com/feedback/feedback[1].php
This code is working great for me, and it was very simple to figure out. But I have one question. I just tested the form and it showed up in my email right away, but I was wondering what the \"Referer\" are was meant for (because it\'s blank for me) and when I try to reply to the person that sent it the reply to address is this
\"-To:\"@node4.c15
again, great script
Why is it that none of my browsers will show the page?
I use RapidWeaver, i have pasted it into the html code.
But Firefox prompts me to download the PHP file, safari just displays the code as text.
Am i doing something wrong? =(
Please help!
rory, Are you running it on an Apache server with PHP? If you are just loading the .php document through explorer it won\'t run.
Hello, we are having trouble with your script because the e-mailing part doesnt work. We have tried the form out and we don\'t get any e-mails. We have tried over 4 email addresses! Plz help!
j-and-f, Maybe check with your web host and see if they allow you to send mail with PHP.