Falloutboy6
Mitglied
Hi,
ich habe hier im Forum folgenden Beitrag gefunden:
http://www.tutorials.de/tutorials215356.html
3ter Beitrag von Blümchen.
Das Ding funktioniert einwandfrei wie ich es mir vorstelle, nur mein Problem ich bekomm es nicht hin, dass ich mehrere Dateien verschicken kann und nicht nur eine wie vordefiniert.
Kann mir da bitte einer helfen, ich bräuchte es für 5 Stück.
Anbei noch mal der Quellcode:
Ich danke euch.
ich habe hier im Forum folgenden Beitrag gefunden:
http://www.tutorials.de/tutorials215356.html
3ter Beitrag von Blümchen.
Das Ding funktioniert einwandfrei wie ich es mir vorstelle, nur mein Problem ich bekomm es nicht hin, dass ich mehrere Dateien verschicken kann und nicht nur eine wie vordefiniert.
Kann mir da bitte einer helfen, ich bräuchte es für 5 Stück.
Anbei noch mal der Quellcode:
PHP:
<?php
# Maximale Größe des Attachments in Bytes:
$max_attach_size = 500000;
?>
<?php
if (isset($_POST["form_submitted"]))
{
// übergebene Variablen ermitteln:
$mailadressen = array();
$mailadressen["Privat"] = "xxx@xxx.de";
$mailadressen["sonstiges"] = "xxx@xxx.de";
$name = $_POST["vorname"]." ".$_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$text = $_POST["text"];
if(isset($mailadressen[$_POST["mailto"]])) {
$mailto = $mailadressen[$_POST["mailto"]];
} else {
die("Keinen gültigen Empfänger ausgewählt!");
}
// Überprüfungen der Daten:
unset($errors);
if ($email != "" and !preg_match("/^[^@]+@.+\.\D{2,5}$/", $email)) $errors[] = "die E-Mail-Adresse sieht nicht richtig aus";
if ($text == "") $errors[] = "es wurde kein Text eingegeben";
if ($_FILES['probe']['size'] > $max_attach_size) $errors[] = "Attachment zu groß (".number_format($_FILES['probe']['size']/1000,0,",","")." KB) - Maximalgröße: ".number_format($max_attach_size/1000,0,",","")." KB";
if (empty($errors))
{
$text = stripslashes($text);
$subject = stripslashes($subject);
if ($name != "") $mail_name=$name; else $mail_name="unbekannt";
if ($subject != "") $mail_subject = $subject; else $mail_subject = "kein Betreff";
if ($email != "") $mail_email = $email; else $mail_email = "xxx@xxx.de";
$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".$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,$mail_subject,"",$mail_header)) $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";
if (@mail($mailto,$mail_subject,$text,$mail_header)) $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";
$header .= "Content-Type: text/plain";
@mail($email, $mail_subject, $copy_mail_text, $header);
}
}
}
if (empty($sent))
{
if(isset($errors))
{
?>
<p align="left" class="caution">Fehler:</p>
<div align="left">
<ul>
<?php foreach($errors as $f) { ?>
<li><?php echo $f; ?></li>
<?php } ?>
</ul>
<br />
<?php
}
?>
</div>
<form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
<div>
<div align="left">
<table width="100%" border="0">
<tr>
<td width="23%" height="25"><p>Name: </p></td>
<td width="77%"><p>
<input name="name" type="text" class="chatfields" value="<?php if (isset($name)) echo htmlentities(stripslashes($name)); else echo ""; ?>" size="32" maxlength="255" />
</p></td>
</tr>
<tr>
<td height="29"><p>E-Mail: </p></td>
<td><p>
<input name="email" type="text" class="chatfields" value="<?php if (isset($email)) echo htmlentities(stripslashes($email)); else echo ""; ?>" size="32" maxlength="255" />
(dahin geht die Antwort) </p></td>
</tr>
<tr>
<td height="27"><p>Betreff:</p></td>
<td><p><b>
<input name="subject" type="text" class="chatfields" value="<?php if (isset($subject)) echo htmlentities(stripslashes($subject)); else echo ""; ?>" size="40" maxlength="40" />
</b></p></td>
</tr>
<tr>
<td height="28"> <p>Art der Anfrage :</p></td>
<td><p><b>
<select name="mailto" class="chatfields">
<option>-- bitte auswählen --</option>
<option value="privat">Privat</option>
<option value="sonstiges">Sonstiges</option>
</select>
</b></p></td>
</tr>
<tr>
<td height="105"><p>Nachricht: </p></td>
<td><p>
<textarea name="text" cols="75" rows="6" class="chatfields"><?php if (isset($text)) echo htmlentities(stripslashes($text)); else echo ""; ?>
</textarea>
</p></td>
</tr>
<tr>
<td><p>Attachment: </p></td>
<td><p>
<input name="probe" type="file" class="chatfields" value="<?php if (isset($_POST['probe'])) echo htmlentities(stripslashes($_POST['probe'])); else echo ""; ?>" size="20"/>
</p></td>
</tr>
</table>
</div>
<p align="left">
<input name="form_submitted" type="submit" class="chatfields" value=">>> Absenden" />
<input type="checkbox" name="copy" value="true" />
Kopie an Absender</p>
</div>
</form>
<?php
}
else
{
if (empty($email)) { ?>
<p align="left"><b>Danke!</b><br />
Nachricht erfolgreich versendet. Allerdings wurde keine E-Mail-Adresse angegeben, ich kann also nicht antworten.</p>
<?php }
else { ?>
<p align="left"><b>Danke!</b><br />
Nachricht erfolgreich versendet.</p>
<?php }
}
?>
Ich danke euch.