PDA

View Full Version : Contact Form


Danny
March 5th, 2005, 20:54
Hey,

http://www.dannyweb.net/proto/contact.htm

Got the page layout exactly how i want etc, but the contact form is working except when i recieve an e-mail the sender is unknown. How do i define a name or something so i can tell easily where the form is from?

<?php
$youremail = "info@dannyweb.org";
$subject = "$select";
$thankyou = "thankyou.php";
if($email == ""){
?>
No email address added. Please go back.<br/>
<?php
}elseif($name == ""){
?>
No name added. Please go back.<br/>
<?php }elseif($message == ""){
?>
No message added. Please go back.<br/>
<?php
}else{


$msg = ereg_replace("\\\'", "'",
$message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail:
$email\nmessage:\n$msg1";
mail($youremail, $subject, $msg, "From:
$email\r\nReply-to: $email\r\n");
?>

Thats the code im using.

Anoop
March 6th, 2005, 19:26
Hey..try this one..slightly modified.


$fromname = "Daniel McClelland";
$youremail = "info@dannyweb.org";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: \"".$fromname."\" <".$email.">\r\n";
$headers .= "Reply-to: ".$email."\r\n";

mail($youremail, $subject, $msg, $headers);

Danny
March 6th, 2005, 19:29
Thats kinda confused me, as im only learning php recently.

Would that replace the whole mail.php? Or simple 'slot' in somewhere?

Anoop
March 6th, 2005, 19:42
Here goes the full script:


<?php
$youremail = "info@dannyweb.org";
$fromname = "Daniel McClelland";
$subject = "$select";
$thankyou = "thankyou.php";
if (email == ""){
?>
No email address added. Please go back.<br/>
<?php
} elseif($name == ""){
?>
No name added. Please go back.<br/>
<?php }elseif($message == ""){
?>
No message added. Please go back.<br/>
<?php
}else{


$msg = ereg_replace("\\\'", "'",
$message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail:
$email\nmessage:\n$msg1";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: \"".$fromname."\" <".$email.">\r\n";
$headers .= "Reply-to: ".$email."\r\n";

mail($youremail, $subject, $msg, $headers);
?>


And also , good coding practise would be to fetch the GET and POST variables from the corresponding global arrays $_POST[] and $_GET[]. :D