PDA

View Full Version : [PHP] Contact Form



Machoman679
17-12-2006, 06:53 PM
Okay i have searched and searched the internet for help and my last choice is to post! :eusa_wall
Can any one help me? I am in need of a [PHP] Contact form that send the details to my email! I can't do it i get loads of errors! :s
Could someone help?

Thanks Machoman679

Matt.
17-12-2006, 06:56 PM
Hi,
I use:

<?php
$nasaadresa = "[email protected]"; //please replace this with your address

$mail = $_POST['Email'];
$porukaa = $_POST['Message'];
$poruka = str_replace("\r", '<br />', $porukaa);
//START OF THANKS MESSAGE
//you may edit $thanks message. this is a message which displays when user sends mail from your site
$thanks = "
<p align='left'><br>
<b>Your message has sucessfuly been sent!<br></b>
#### MESSAGE TEXT ####
<br><br>
$poruka
<br><br>
#### END OF MESSAGE ####
<br><br>
You will recive a copy of the message at your email address <b>($mail).<br>We will reply you soon as possible<br></b></p>";
//do not edit nothing below this line until comment (ME) say so if you don't have skills with PHP
//END OF THANKS MESSAGE

if($_POST['submitform'])
{

$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$require = $_POST['require'];
$browser = $HTTP_USER_AGENT;
$ip = $_SERVER['REMOTE_ADDR'];

$dcheck = explode(",",$require);
while(list($check) = each($dcheck))
{
if(!$$dcheck[$check]) {
$error .= "You have not filled this filed(s): <b>$dcheck[$check]</b>.<br>";
}
}
if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[[email protected]]+$", $Email))){
$error .= "Wrong e-mail.<br>This e-mail address <b>$Email</b> - is not valid. Please enter correct e-mail address.";
}
if($error)
{
echo $error;
echo '<br><a href="#" onClick="history.go(-1)">Please try again.</a>';
}
else
{
//START OF INCOMING MESSAGE (this message goes to your inbox)
$message = "
Name: $Name:
E-mail: $Email

Message: $Message

-----------------------------
Browser: $browser
IP: $ip
";
//END OF INCOMING MESSAGE (this message goes to your inbox)

$subject = "Message from www.yoursite.com - Message was sent by $Name"; //subject OF YOUR INBOX MESSAGE sent to you

$subject2 = "You have succesfully sent message from www.yoursite.com!"; //subject of OUTGOING MESSAGE - edit this
//OUTGOING MESSAGE TEXT
$message2 = "You have sent a message to site admin of a www.yoursite.com:
-----------------------------
From: $Name:
E-mail: $Email

Message: $Message

-----------------------------
";
//END OF outgoing MESSAGE


mail($nasaadresa,"$subject","$message","From: $Name <$Email>");
mail($Email,"$subject2","$message2","From: <$nasaadresa>");
echo "$thanks";
}
}
else{
//this is contact form down here, please edit if you know what are you doing... or the contact form may not be working.
echo '
<p align="center"><br><b>Please contact us:</b></p><br><br>
<form name="contactform" action="'.$PHP_SELF.'" method="post">
<input type="hidden" name="require" value="Name,Email,Message">
<table width="444" align="center">
<tr>
<td colspan="2" align="center">
<p></td>
</tr>
<tr>
<td valign="top" align="right"><b>Name:</b></td>
<td valign="top">
<input name="Name" size="30">
</td>
</tr>
<tr>
<td valign="top" align="right"><b>E-mail:</b></td>
<td valign="top">
<input name="Email" size="30">
</td>
</tr>
<tr>
<td valign="top" align="right"><b>Message:</b></td>
<td valign="top">
<textarea name="Message" rows="10" cols="30"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><p align="right"><br>
<input type="submit" value="Send" name="submitform">
<input type="reset" value="Reset" name="reset"></p>
</td>
</tr>
</table>
</form>';
}
?>

You just need to edit the [email protected] and the www.yoursite.com :).

Want to hide these adverts? Register an account for free!