ich bekomme das mit dem tutorial nicht so hin wie ich mir das vorstelle.
kann man die fehlermeldung nicht einfach hinter das feld verweisen oder so ?
dier ist das formular. ich bitte um hilfe !
PHP-Code:
<?php
# Adresse, an die die Formulardaten gesendet werden sollen:
$mailto = "eclipse_240_hp@gmx.net";
# Maximale Größe des Attachments in Bytes:
$max_attach_size = 2000000;
?>
<?php
if (isset($_POST["form_submitted"]))
{
// übergebene Variablen ermitteln:
$anrede = $_POST['anrede'];
$name = $_POST['name'];
$vorname = $_POST['vorname'];
// Überprüfungen der Daten:
unset($errors);
if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "die E-Mail-Adresse ist fehlerhaft!";
if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Attachment zu groß (".number_format($_FILES['probe']['size']/2000000,0,",","")." KB) - Maximalgröße: ".number_format($max_attach_size/2000000,0,",","")." KB";
if(empty($name))$errors[] = "Bitte geben sie Ihren Namen ein!";
if(empty($vorname)) $errors[] = "Bitte geben Sie Ihren Vornamen ein!";
if(empty($_POST['probe'])) $errors[] = "Bitte fügen Sie eine Bilddatei von ihrem Rechner ein!";
if (empty($errors))
{
$text = stripslashes($text);
$subject = stripslashes($subject);
if ($name != "") $mail_name=$name; else $mail_name="unbekannt";
if ($email != "") $mail_email = $email; else $mail_email = "email@unknown.xyz";
$ip = $_SERVER["REMOTE_ADDR"];
// Wenn Attachment, dann MIME-Mail erstellen:
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "")
{
// Datei einlesen und codieren:
$datei_content = fread(fopen($_FILES['probe']['tmp_name'],"r"),filesize($_FILES['probe']['tmp_name']));
$datei_content = chunk_split(base64_encode($datei_content),76,"\n");
// Boundary festlegen:
$boundary = md5(uniqid(rand()));
// Mail-Header:
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: ".$ip."\n";
$mail_header .= "MIME-Version: 1.0\n";
$mail_header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$mail_header .= "This is a multi-part message in MIME format.\n";
// Mail-Text:
$mail_header .= "--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
$mail_header .= "\n\n".$name;
$mail_header .= "\n\n".$vorname;
$mail_header .= "\n\n".$text;
// Attachment:
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: ".$_FILES['probe']['type']."; name=\"".$_FILES['probe']['name']."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"".$_FILES['probe']['name']."\"";
$mail_header .= "\n\n".$datei_content;
// Ende:
$mail_header .= "\n--".$boundary."--";
// Sende E-Mail und gebe Fehler bzw. Bestaetigung aus
if (@mail($mailto ,"Bestellung","",$mail_header,"-f [email]Mail@mydomain.de[/email]")) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
}
// kein Attachment, normale E-Mail:
else
{
$mail_header = "From: ".$mail_name." <".$mail_email.">\n";
$mail_header .= "X-Sender-IP: $ip\n";
$mail_header .= "Content-Type: text/plain";
$mail_header .= "\n\n".$name;
$mail_header .= "\n\n".$vorname;
$mail_header .= "\n\n".$text;
if (@mail($mailto,"Bestellung:",$text,$mail_header,"-f [email]Mail@mydomain.de[/email]")) $sent = true; else $errors[] = "keine Verbindung zum Mailserver - bitte nochmal versuchen";
}
// Kopie an Absender:
if (isset($sent) && isset($email) && $email != "" && isset($_POST['copy']))
{
if (isset($_FILES['probe']['name']) && trim($_FILES['probe']['name']) != "") $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text."\n\nAttachment: ".$_FILES['probe']['name']; else $copy_mail_text = "Kopie der versendeten E-Mail:\n\n".$text;
$header= "From: ".$mailto."\n";
$header .= "X-Sender-IP: ".$ip."\n";
// Mail-Text:
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\n\n".$name;
$mail_header .= "\n\n".$vorname;
$mail_header .= "\n\nFrage:".$text;
@mail($email, "Vielen Dank", $copy_mail_text, $mail_header,"-f [email]Mail@mydomain.de[/email]");
}
}
}
if (empty($sent))
{
if(isset($errors))
{
?><p class="caution">Fehler:</p><ul><?php foreach($errors as $f) { ?>[*]<?php echo $f; ?><?php } ?>[/list]<?php
}
?><form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"><div>
<table align="center">
<tr>
<td>Alle Felder mit einem <font color="#FF0000">*</font> sind auszufüllen!</td>
</tr>
</table>
<table align="center">
<tr>
<td>Anrede:</td>
<td> <select name="anrede">
<option value="Herr"<?php if (isset($anrede)== 'Herr') echo 'SELECTED="SELECTED"' ?>>Herr</option>
<option value="Frau"<?php if (isset($anrede)== 'Frau') echo 'SELECTED="SELECTED"' ?>>Frau</option>
</td>
</tr>
<tr>
<td>Name: <font color="#FF0000">*</font></td>
<td><input type="text" name="name" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo $errors[name]; ?>" size="21" /> </td>
</tr>
<tr>
<td>Vorname: <font color="#FF0000">*</font></td>
<td><input type="text" name="vorname" value="<?php if (isset($vorname)) echo htmlentities(stripslashes($vorname)); else echo ""; ?>" size="21" /> </td>
</tr>
</table>
<table align="center">
<tr>
<td><div align="center"> Stellen Sie hier Bitte Ihre Fragen.</div></font></td>
</tr>
<tr>
<td><textarea name="text" cols="50" rows="7"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?></textarea> </td>
</tr>
</table>
<table align="center">
<tr>
<td><div align="center">Wählen Sie eine Bilddatei von ihrem Rechner aus <font color="#FF0000">*</font>:
(Die optimale Bildgröße ist 230x230 px).</div></font> </td>
</tr>
<tr>
<td> <input type="file" size="45" name="probe" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" /></td>
</tr>
</table>
<table align="center">
<tr>
<td> <input type="submit" name="form_submitted" value="Senden" /></td>
<td> <input type="reset"></td>
<td> <input type="checkbox" name="copy" value="true" /> Kopie an Ihre E-Mail</font></td>
</tr>
</table>
</form>
<?php
}else{if(empty($email)){header ("Location: http://www.example.com");}
else{header ("Location: http://www.example.com");}}
?>
danke !