Schönen guten Abend,
Wie der Titel schon sagt bräuchte ich Hilfe bei einem Kontaktformular.
Die Aufgabe besteht darin ein Kontaktformular für eine Partnerbörse zu erstellen, dass die eingegebenen Daten in eine MySQL Tabelle überträgt und eine Email an die angegebene Mail verschickt.
Ich habe versucht das ganze über ein AJAX Kontaktformular zu verwirklichen.
Durch einige persönliche Probleme bin ich da leider etwas in Verzug geraten und jetzt habe ich ein Problem bei der Fehler Lösung.
Zu erst ist hier mein Scripte:
Index.php:
mail.php:
scripts.js:
style.css
Das Problem:
Wenn ich das Kontaktformular hochlade und ausfülle sagt er mich das alles erfolgreich verlief, aber es werden keine Daten in die Datenbank eingetragen, und eine Email wird auch nicht verschickt.
Wie der Titel schon sagt bräuchte ich Hilfe bei einem Kontaktformular.
Die Aufgabe besteht darin ein Kontaktformular für eine Partnerbörse zu erstellen, dass die eingegebenen Daten in eine MySQL Tabelle überträgt und eine Email an die angegebene Mail verschickt.
Ich habe versucht das ganze über ein AJAX Kontaktformular zu verwirklichen.
Durch einige persönliche Probleme bin ich da leider etwas in Verzug geraten und jetzt habe ich ein Problem bei der Fehler Lösung.
Zu erst ist hier mein Scripte:
Index.php:
Code:
<!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> <title>Kontaktier mich!</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="fields"> <h1>Contact Form</h1> <form action="" method="post" id="contactForm" class="dl_form"> <dl><dt>Name</dt><dd> <input type="text" name="name" id="name" class="" /> </dd></dl> <dl><dt>Email</dt><dd> <input type="text" name="email" id="email" class="" /> </dd></dl> <dl><dt>Alter</dt><dd> <input type="text" name="alter" id="alter" class="" /> </dd></dl> <dl><dt>Wohnort</dt><dd> <input type="text" name="wohnort" id="wohnort" class="" /> </dd></dl> <dl><dt>Groesse</dt><dd> <input type="text" name="groesse" id="groesse" class="" /> </dd></dl> <dl><dt>Hautfarbe</dt><dd> <input type="text" name="hautfarbe" id="hautfarbe" class="" /> </dd></dl> <dl><dt>Haarfarbe</dt><dd> <input type="text" name="haarfarbe" id="haarfarbe" class="" /> </dd></dl> <dl><dt>Lieblingsmusik:</dt><dd> <input type="text" name="lieblingsmusik" id="lieblingsmusik" class="" /> </dd></dl> <dl><dt>Kommentar</dt><dd> <textarea name="kommentar" style="width:300px; height:150px;" id="kommentar" class="" ></textarea> </dd></dl> <dl><dt> </dt><dd> <input type="submit" value="submit" /> </dd></dl> </form> </div> </div> </body> </html>
PHP-Code:
<?php
##############################################################################################################
$server = 'localhost';
$username = 'meinbenutzername';
$password = 'meinpasswort';
$database = 'meinedatenbank';
$connect = mysql_connect($server, $username, $password ) or die(mysql_error.'error connecting to db');
//select database
mysql_select_db ($database, $connect) or die(mysql_error.'error selecting db');
if(!empty($_POST)){
$name = $_POST['name'];
$email = $_POST['email'];
$alter = $_POST['alter'];
$wohnort = $_POST['wohnort'];
$groesse = $_POST['groesse'];
$hautfarbe = $_POST['hautfarbe'];
$haarfarbe = $_POST['haarfarbe'];
$lieblingsmusik = $_POST['lieblingsmusik'];
$kommentar = $_POST['kommentar'];
if(!empty($name) && !empty($email) && !empty($alter) &&
!empty($wohnort) && !empty($groesse) && !empty($hautfarbe) &&
!empty($haarfarbe) && !empty($lieblingsmusik) && !empty($kommentar))
{
echo json_encode(array(
'error' => false,
));
exit;
mysql_query("INSERT into kontakt (id, name, email, alterr, wohnort, groesse, hautfarbe, haarfarbe, lieblingsmusik, kommentar )
VALUES ('', '".$name."', '".$email."', '".$alter."',
'".$wohnort."', '".$groesse."', '".$hautfarbe."',
'".$haarfarbe."', '".$lieblingsmusik."',
'".$kommentar."' )") or die(mysql_error());
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$email."\r\n";
$to = $email;
$subject = 'Contact Form';
$body = 'From: <br /> Vorname: '.$name.' <br />E-mail: '.$email.' <br />Kommentar: '.$kommentar;
$mail = mail($to, $subject, $headers, $body);
}else{
echo json_encode(array(
'error' => true,
'msg' => "Du hast noch nicht alle Felder ausgefüllt!"
));
exit;
}
}
PHP-Code:
$(function(){
//CONTACT FORM AJAX SUBMIT
$('#contactForm').submit(function(){
$.ajax({
url:'mailer.php',
type : 'POST',
dataType: 'json',
data: $(this).serialize(),
success: function(data){
if(data.error){
$('#error').css('display','block');
}else {
$('#note').show();
$('#error').hide();
$("#fields").hide();
}
}
})
return false;
})
})
PHP-Code:
/* CSS Document */
html {
overflow-y:scroll;
}
html, body {
margin:0;
padding:0;
font-family:Arial, sans-serif;
font-size:12px;
color:#474747;
}
h1 {
font-size:20px;
color:#b03945;
font-weight:normal;
font-family:Helvetica,sans-serif;
border-bottom:1px solid #ccc;
padding-bottom:5px;
}
#main {
margin:0 auto;
width:900px;
position:relative;
}
.dl_form { }
.dl_form dl {
clear:both;
margin-bottom:7px;
border-bottom:1px dashed #ccc;
padding-bottom:7px;
}
.dl_form dl dt {
float:left;
margin-top:2px;
}
.dl_form dl dd {
margin-left:120px;
}
.dl_form input[type="submit"] {
background-color:#0186b3;
border:1px solid #7c7c7c;
padding:3px 15px;
color:#fff;
cursor:pointer;
font-family:Helvetica, sans-serif;
font-size:14px;
}
.dl_form input[type="text"] {
background-color:#edfaff;
border:1px solid #7c7c7c;
padding:5px 2px;
color:#404040;
opacity:0.7;
}
.dl_form textarea:hover,
.dl_form textarea:focus,
.dl_form input[type="text"]:focus,
.dl_form input[type="text"]:hover {
background-color:#e2f1f6;
}
.dl_form textarea {
background-color:#edfaff;
border:1px solid #7c7c7c;
height:70px;
padding:2px;
width:250px;
color:#404040;
}
#note,
#error {
display:none;
}
#error {
height:20px;
background:red;
position:absolute;
top:40px;
right:0;
color:#fff;
padding:5px 10px;
font-size:16px;
}
Das Problem:
Wenn ich das Kontaktformular hochlade und ausfülle sagt er mich das alles erfolgreich verlief, aber es werden keine Daten in die Datenbank eingetragen, und eine Email wird auch nicht verschickt.
Kommentar