formmail problemer
Hejer der nogen der kan hjælpe mig med at få denne til at virke?
på forhånd tak
<head>
<title></title>
</head>
<body bgcolor="#B5B5B5">
<?
if((isset($_POST['navn'])) && (isset($_POST['email'])) && (isset($_POST['emne'])) && (isset($_POST['besked']))){
mail("min@mail.dk", $_POST['emne'] , $_POST['navn']." har skrevet denne besked:\n\n".$_POST['besked'] , "From: ".$_POST['email']);
echo "<b>Tak for din mail.<br><br>Tak for din mail</b>";
} else {
?> <br>
<form method=post action="<? echo $_SERVER['PHP_SELF']; ?>">
<div align="center">
<center>
<table border="1" width="15%" cellspacing="5" cellpadding="0" bordercolor="#B5B5B5" bgcolor="#B5B5B5">
<tr>
<td width="37%"><font color="#101842" size="1" face="Verdana">
Dit navn :</font></td>
<td width="74%"><font color="#101842" size="1" face="Verdana">
Din e-mail :</font></td>
</tr>
<tr>
<td width="37%"><b><font face="Arial" size="2">
<input type=text name=navn size="18" style="font-family: Verdana; font-size: 8 pt; color: #101842; border: 1 solid #000000"></font></b></td>
<td width="74%"><b><font face="Arial" size="2">
<input type=text name=email size="18" style="font-family: Verdana; font-size: 8 pt; color: #101842; border: 1 solid #000000"></font></b></td>
</tr>
<tr>
<td width="100%" colspan="2"><font size="1" face="Verdana" color="#101842">
Emne :</font></td>
</tr>
<tr>
<td width="100%" colspan="2"><b><font face="Arial" size="2">
<input type=text name=emne size="39" style="font-family: Verdana; font-size: 8 pt; color: #101842; border: 1 solid #000000"></font></b></td>
</tr>
<tr>
<td width="100%" colspan="2"><font face="Verdana" color="#101842" size="1">
Din besked :</font></td>
</tr>
<tr>
<td width="100%" colspan="2"><b><font face="Arial" size="2">
<textarea name=besked rows=5 cols="38" style="font-family: Verdana; font-size: 8 pt; color: #101842; border: 1 solid #000000"></textarea></font></b></td>
</tr>
<tr>
<td width="100%" colspan="2">
<input type=submit value=" Send " style="background-color: #FFFFFF; font-family: Verdana; color: #101842; font-size: 8 pt; border: 1 solid #000000">
<input type="reset" value=" Slet " style="font-family: Verdana; font-size: 8 pt; color: #101842; background-color: #FFFFFF; border: 1 solid #000000">
</td>
</tr>
</table>
</center>
</div>
</form>
<?
}
?>
formmail.php
<?php
$fm = new Form_Mail();
class Form_Mail
{
/**
* Form_Mail
*/
/* set vars */
var $error_message = "";
var $print_array = array();
var $config_vars_array = array("recipient" => "",
"from" => "",
"subject" => "Kontakt Form Fra Din Hjemmeside",
"email" => "",
"redirect" => "",
"required" => "",
"env_report" => "",
"sort" => "",
"print_config" => "",
"print_blank_fields" => "0",
"title" => "Kontakt Form Fra Din Hjemmeside",
"return_link_url" => "",
"return_link_title" => "Tilbage",
"missing_fields_redirect" => "",
"missing_fields_message" => "En eller flere felter mangler prøv igen.<br>\n<a onclick=\"history.go(-1)\" style=\"color: black;\">Klik her</a> for at vende tilbage.<br>\n",
"background" => "",
"bgcolor" => "#ffffff",
"text_color" => "#000000",
"link_color" => "black",
"vlink_color" => "black",
"alink_color" => "black",
"thank_you_message" => "Tak fordi du udfyldte denne form",
);
var $referers_array = array();
var $valid_env = array('REMOTE_ADDR','REMOTE_PORT','HTTP_REFERER','HTTP_USER_AGENT');
function Form_Mail()
{
/**
* Form_Mail();
*/
$this->referers_array = array($_SERVER["HTTP_HOST"]);
/* proccess form */
$this->set_arrays();
$this->check_referer();
$this->check_recipient();
$this->check_required_fields();
$this->send_form();
$this->display_thankyou();
}
function set_arrays()
{
/**
* set_arrays();
*/
foreach ($_POST as $key=>$value) {
if (isset($this->config_vars_array[strtolower("$key")])) {
$key = strtolower($key);
$this->config_vars_array["$key"] = $value;
} else {
$this->print_array["$key"] = $value;
}
}
/* create an array of config vars to print in message and add them to $print_array */
if ($this->config_vars_array["print_config"] != "") {
$print_config_array = explode(",", $this->config_vars_array["print_config"]);
foreach ($print_config_array as $key=>$value) {
$value = trim($value);
$this->print_array["$value"] = $_POST["$value"];
}
}
/* sort $print_array, if requested */
if ($this->config_vars_array["sort"] == "alphabetic") {
/* sort alphabetically */
$print_array_keys_array = array_keys($this->print_array);
sort($print_array_keys_array);
foreach ($print_array_keys_array as $key=>$value) {
$tmp_array["$value"] = $this->print_array["$value"];
}
unset($this->print_array);
$this->print_array = $tmp_array;
} elseif ($this->config_vars_array["sort"] != "") {
/* sort according to $sort */
$sort_array = explode(",", $this->config_vars_array["sort"]);
foreach ($sort_array as $key=>$value) {
$value = trim($value);
$tmp_array["$value"] = $this->print_array["$value"];
}
foreach ($this->print_array as $key=>$value) {
if (!isset($tmp_array["$key"])) {
$tmp_array["$key"] = $this->print_array["$key"];
}
}
unset($this->print_array);
$this->print_array = $tmp_array;
}
/* add environmental vars, if set */
if ($_POST["env_report"] != "") {
$env_vars_array = explode(",", $_POST["env_report"]);
foreach ($env_vars_array as $key=>$value) {
$value = trim($value);
if (in_array("$value", $this->valid_env)) {
$this->print_array["$value"] = $_SERVER["$value"];
}
}
}
/* remove blank fields, if requested */
if ($this->config_vars_array["print_blank_fields"] == "0") {
foreach ($this->print_array as $key=>$value) {
if ($value == "") {
unset($this->print_array["$key"]);
}
}
}
}
function check_referer()
{
/**
* check_referer();
*/
$referer = $_SERVER["HTTP_REFERER"];
foreach ($this->referers_array as $key=>$value) {
if ((eregi("^http://$value", $referer)) || (eregi("^https://$value", $referer))) {
return true;
}
}
$this->error_message = "<b>$referer</b> har ikke rettigheder til at benytte denne form.<br>\n";
$this->display_error();
return false;
}
function check_recipient()
{
/**
* check_recipient();
*/
$recipient_array = explode(",", $this->config_vars_array["recipient"]);
foreach ($recipient_array as $key=>$email) {
$email = trim($email);
if(!eregi("^[0-9a-z]([-_.+]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,7}$", "$email")) {
$this->error_message = "Recipient email is either not set, or is not a valid email address.";
$this->display_error();
return false;
}
}
return true;
}
function check_required_fields()
{
/**
* check_required_fields();
*/
if ($this->config_vars_array["required"] != "") {
$required_fields_array = explode(",", "$_POST[required]");
foreach ($required_fields_array as $key=>$required_field) {
$required_field = trim($required_field);
if ($_POST["$required_field"] == "") {
$this->display_missing_fields_error();
return false;
}
}
}
return true;
}
function send_form()
{
/**
* send_form();
*/
$mailBody = "";
foreach ($this->print_array as $key=>$value) {
if (is_array($value)) {
foreach ($value as $key2=>$value2) {
$mailBody .= "$key: $value2\n";
}
} else {
$mailBody .= "$key: $value\n";
}
}
$mailHeaders = "From: " . $this->config_vars_array["email"] . "\n";
if(mail($this->config_vars_array["recipient"], $this->config_vars_array["subject"], $mailBody, $mailHeaders)) {
return true;
} else {
return false;
}
}
function display_thankyou()
{
/**
* display_thankyou();
*/
if($this->config_vars_array["redirect"] == "") {
$this->display_header();
print "<h2>" . $this->config_vars_array["thank_you_message"] . "</h2><br>\n";
if ($this->config_vars_array["return_link_url"] != "") {
print "<br>\n";
print "<a href=\"" . $this->config_vars_array["return_link_url"] . "\">" . $this->config_vars_array["return_link_title"] . "</a><br>\n";
}
$this->display_footer();
} else {
header("Location: " . $this->config_vars_array["redirect"]);
}
exit;
}
function display_missing_fields_error()
{
/**
* display_error();
*/
if($this->config_vars_array["missing_fields_redirect"] == "") {
$this->display_header();
print $this->config_vars_array["missing_fields_message"];
$this->display_footer();
} else {
header("Location: " . $this->config_vars_array["missing_fields_redirect"]);
}
exit;
}
function display_error()
{
/**
* display_error();
*/
$this->display_header();
print $this->error_message;
$this->display_footer();
exit;
}
function display_header()
{
/**
* display_header();
*/
$bgcolor = $this->config_vars_array["bgcolor"];
$text_color = $this->config_vars_array["text_color"];
$background = $this->config_vars_array["background"];
$link_color = $this->config_vars_array["link_color"];
$vlink_color = $this->config_vars_array["vlink_color"];
$alink_color = $this->config_vars_array["alink_color"];
print "<html>\n";
print "<head>\n";
print "<title>$title</title>\n";
print "</head>\n";
print "<body text=\"$text_color\" background=\"$background\" bgcolor=\"$bgcolor\" link=\"$link_color\" alink=\"$alink_color\" vlink=\"$vlink_color\">\n";
print "<div align=\"center\">";
}
function display_footer()
{
/**
* display_footer();
*/
print "</div>\n";
print "</body>\n";
print "</html>\n";
}
}
?>
