Ich müsse das Kontaktformular in die Index.php integriert haben, sodass das es funktioniert. Das Formular stammt einem anderen Theme.
Kontaktformular:
PHP
<?php
/*
Template Name: Contact
*/
$cp_question = "1+3 = ?";
$cp_answer = "4";
?>
<?php get_header();?>
<div id="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<?php
//validate email adress
function is_valid_email($email)
{
return (eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $email));
}
function is_valid_user($answer)
{
global $cp_answer;
if ($answer == $cp_answer) { return true; } else { return false;}
}
//clean up text
function clean($text)
{
return stripslashes($text);
}
//encode special chars (in name and subject)
function encodeMailHeader ($string, $charset = 'UTF-8')
{
return sprintf ('=?%s?B?%s?=', strtoupper ($charset),base64_encode ($string));
}
$cp_name = (!empty($_POST['cp_name'])) ? $_POST['cp_name'] : "";
$cp_email = (!empty($_POST['cp_email'])) ? $_POST['cp_email'] : "";
$cp_url = (!empty($_POST['cp_url'])) ? $_POST['cp_url'] : "";
$cp_ans = (!empty($_POST['cp_ans'])) ? $_POST['cp_ans'] : "";
$cp_message = (!empty($_POST['cp_message'])) ? $_POST['cp_message'] : "";
$cp_message = clean($cp_message);
$error_msg = "";
$send = 0;
if (!empty($_POST['submit'])) {
$send = 1;
if (empty($cp_name) || empty($cp_email) || empty($cp_message) || empty($cp_ans)) {
$error_msg.= "<p style='color:#a00'><strong>Bitte fülle alle erforderlichen Felder aus.</strong></p>\n";
$send = 0;
}
if (!is_valid_email($cp_email)) {
$error_msg.= "<p style='color:#a00'><strong>Deine E-Mail-Adresse ist ungültig.</strong></p>\n";
$send = 0;
}
if (!is_valid_user($cp_ans)) {
$error_msg.= "<p style='color:#a00'><strong>Falsche Antwort auf die AntiSpam-Frage.</strong></p>\n";
$send = 0;
}
}
if (!$send) { ?>
<h2 class="post-title"><?php the_title(); ?></h2>
<div class="post-content">
<?php the_content("Den ganzen Beitrag lesen »");
?>
<p class="meta">* - erforderlich</p>
<?php echo $error_msg;?>
<form method="post" action="<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" id="contactform">
<fieldset>
<strong>Name</strong>*<br/>
<input type="text" class="text" id="cp_name" name="cp_name" value="<?php echo $cp_name ;?>" /><br/><br/>
<strong>E-Mail</strong>*<br/>
<input type="text" class="text" id="cp_email" name="cp_email" value="<?php echo $cp_email ;?>" /><br/><br/>
<strong>Webseite</strong><br/>
<input type="text" class="text" id="cp_url" name="cp_url" value="<?php echo $cp_url ;?>" /><br/><br/>
<strong>AntiSpam Frage:<?php echo $cp_question; ?> </strong>*<br/>
<input type="text" class="text" id="cp_ans" name="cp_ans" value="<?php echo $cp_ans ;?>" /><p class="meta">[Just to prove you are not a spammer]</p><br/>
<strong>Nachricht</strong>*<br/>
<textarea id="cp_message" name="cp_message" rows="10" cols="100%"><?php echo $cp_message ;?></textarea><br/><br/>
<input type="submit" id="submit" name="submit" value="Nachricht absenden" />
</fieldset>
</form>
</div>
<?php
} else {
$displayName_array = explode(" ",$cp_name);
$displayName = htmlentities(utf8_decode($displayName_array[0]));
$header = "MIME-Version: 1.0\n";
$header .= "Content-Type: text/plain; charset=\"utf-8\"\n";
$header .= "From:" . encodeMailHeader($cp_name) . "<" . $cp_email . ">\n";
$email_subject = "[" . get_settings('blogname') . "] " . encodeMailHeader($cp_name);
$email_text = "From......: " . $cp_name . "\n" .
"Email.....: " . $cp_email . "\n" .
"Url.......: " . $cp_url . "\n\n" .
$cp_message;
if (@mail(get_settings('admin_email'), $email_subject, $email_text, $header)) {
echo "<h2>Hallo " . $displayName . ",</h2><p>danke für Deine Nachricht! Ich melde mich so bald wie möglich.</p>";
}
}
?>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>
Alles anzeigen
Hier soll das Kontaktformular rein:
PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?></title>
<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/scripts/layers.js"></script>
<style type="text/css" media="screen">
#wrapper { background: url("<?php bloginfo('stylesheet_directory'); ?>/img/wrapbg.gif") repeat-y; }
</style>
<?php wp_get_archives('type=monthly&format=link'); ?>
<?php wp_head(); ?>
</head>
<body>
<div id="wrapper">
<div id="subwrapper">
<?php require_once('header.php'); ?>
<div id="sidebar">
<?php require_once('sidebar.php'); ?>
</div>
<div id="main">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', ') ?> <?php the_time('F jS, Y') ?> by <?php the_author() ?> | <?php edit_post_link('Edit','','|'); ?> <?php comments_popup_link('No comments', '1 comment', '% comments'); ?></p>
</div>
<?php comments_template(); ?>
<?php endwhile; ?>
<p align="center"><?php next_posts_link('« Previous Entries') ?> <?php previous_posts_link('Next Entries »') ?></p>
<?php else : ?>
<h2 align="center">Not Found</h2>
<p align="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div>
<?php require_once('footer.php'); ?>
</div>
</div>
</body>
</html>
Alles anzeigen
Danke