mehrere dateien mit formular senden

F

fercules

dieses script sendet ein formular mit anhang als email. leider kann man bisher nur eine datei damit abschicken. was müsste man tun, damit man mit diesem script z.b. 5 statt 1 upload gleichzeitig machen könnte? hab schon einges erfolglos probiert und langsam keinen nerv mehr

<?php


$websitename="phMailer 1.3"; //Website Name


$allowtypes=array("zip", "rar", "txt", "doc", "jpg", "jpeg", "png", "gif", "ai", "bmp", "tiff", "tif", "pdf", "eps", "psd", "psp");
$myemail="you@yourdomain.com"; // What's your email address?
$priority="3"; // What priority should I send the mail? 1 is Urgent, 10 Is low. 3 Is default.
$allowattach="1"; // Should we allow visitors to attach *.zip files? 1=yes, 0=no.


$submitvalue=" Send Email "; // Value for the Submit Button
$resetvalue=" Reset Form "; // Value for the Reset Button
$defaultsubject="No Subject"; // Default subject header? This will be sent if the user does not specify a subject.
$thanksmessage="Thank you! Your email has been sent, we will respond shortly."; //Your thank you message, displays after the email has been sent.


$twidth="450"; // Table Width
$tableborder="1"; // Show table border? 1=yes, 0=no.
$tbordercolor="#000000"; // Table Border Color
$thead="#FFFFFF"; // Table head background Color
$tbody="#FFFFFF"; // Table Body Background Color

$bgcolor="#FFFFF"; // Page bg Color

$fontface="Verdana,Arial"; // Font face
$fonthead="#000000"; // Font Head Color
$fontheadsize="11"; // Font Head Size
$fontbody="#000000"; // Font BodyColor
$fontbodysize="10"; // Font Body Size

/*
//================================================================================
* Attention
//================================================================================
: Don't edit below this line unless you know some php. Editing some variables or other stuff could cause undeseriable results
*/

function get_ext($key) {
return(strtolower(substr(strrchr($key, "."), 1)));

}

If($_POST['domail']) {

extract($_POST);

If($allowattach) {
$attachment=$_FILES['attachment']['tmp_name'];
$attachment_type=$_FILES['attachment']['type'];
}

If ($yourname=="") {
$error = "1";
$error_text .= "You did not enter your name!<br />";
}

If ($youremail=="") {
$error = "1";
$error_text .= "You did not enter your email!<br />";
}

If($emailsubject=="") {
$emailsubject=$defaultsubject;
}

If ($youremail) {
If (!eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$",$youremail)){
$error = "1";
$error_text .= "Invalid Email Address!<br />";
}
}

If ($yourmessage=="") {
$error = "1";
$error_text .= "You did not enter a message!<br />";
}

If($allowattach) {

foreach($allowtypes as $it) {
$types .="*.".$it.",";
}

If($attachment) {
$ext=get_ext($_FILES[attachment][name]);
If(!in_array($ext, $allowtypes)) {
$error = "1";
$error_text .= "Invalid extension for your attchment, only ".$types." are allowed!<br />";
}
}
}

If($error=="1") {

$disperrors=$error_text;

} Else {

$headers = "From: ".$yourname." <".$youremail.">\n";
$headers .= "Reply-To: ".$yourname." <".$youremail.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"MIME_BOUNDRY\"\n";
$headers .= "X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
$headers .= "X-Mailer: phMailerv1.3\n";
$headers .= "X-Priority: ".$priority."\n";
$headers .= "Return-Path: <".$myemail.">\n";
$headers .= "This is a multi-part message in MIME format.\n";

If($allowattach) {
If($attachment) {
$fp=@fopen($attachment,"r");
$str=@fread($fp, filesize($attachment));
$str=@chunk_split(base64_encode($str));
}
}

$message = "--MIME_BOUNDRY\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= "$yourmessage";
$message .= "\n";

If($allowattach) {
If($attachment) {
$message .= "--MIME_BOUNDRY\n";
$message .= "Content-Type: application/octet-stream; name=\"" . $_FILES['attachment']['name'] . "\"\n";
$message .= "Content-disposition: attachment\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "\n";
$message .= "$str\n";
$message .= "\n";
$message .= "--MIME_BOUNDRY--\n";
}
}

If(!mail($myemail,$emailsubject,$message,$headers)) {
exit("There has been an error, please contact the admin");
}

Echo("<div align=\"center\">".$thanksmessage."</div>");
exit(cp());

}

}

//Please do not remove, I worked hard on this script! :(.

function cp() {
Echo("<br /><br /><div align=\"center\" class=\"body\">Powered By: <a href=\"http://www.phphq.net?script=phMailer\" target=\"_blank\"><b>phMailer v1.3</b></a></div>\n");
}

/*
//================================================================================
* Start the form layout
//================================================================================
:- Start the form, if you are editing this form, please remember to escape all quotes " with a backslash, an example would be <input type=\"text\">
:- If you do not do this, you will get phrase errors.
:- Also, please remember that if you change values in this form, the script may not work how it was originally meant to.
*/


Echo("<html>\n");
Echo("<head>\n");
Echo("<title>".$websitename." - Powered By phMailer v1.3</title>\n");
Echo("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n");
Echo("<style type=\"text/css\">\n");
Echo("body{background-color:".$bgcolor.";}\n");
Echo("a:link {text-decoration:none; color:".$fontbody.";}\n");
Echo("a:visited {text-decoration:none; color:".$fontbody.";}\n");
Echo(".head{font-family:".$fontface."; font-size:".$fontheadsize."; color:".$fonthead."; font-weight:bold;}\n");
Echo(".body{font-family:".$fontface."; font-size:".$fontbodysize."; color:".$fontbody.";}\n");
Echo("input { font-family:".$fontface."; font-size:".$fontbodysize."px; color:".$fonthead."; border:1px solid ".$tbordercolor."; background-color:".$thead.";}\n");
Echo("</style>\n");
Echo("</head>\n");
Echo("<body>\n");
Echo("<div align=\"center\" class=\"body\"><b>".$disperrors."</b></div>");
Echo("<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\""); If($allowattach){Echo(" enctype=\"multipart/form-data\"");}Echo(">\n");
Echo("<table cellspacing=\"0\" cellpadding=\"1\" border=\"".$tborder."\" style=\"border-collapse: collapse\" bordercolor=\"".$tbordercolor."\" align=\"center\" width=\"".$twidth."\" bgcolor=\"".$tbody."\" class=\"body\">\n");
Echo("<tr>\n");
Echo("<td colspan=\"2\" align=\"center\" bgcolor=\"".$thead."\" class=\"head\">".$websitename."</td>\n");
Echo("</tr>\n");
Echo("<tr>\n");
Echo("<td width=\"30%\" >Your Name:</td>\n");
Echo("<td width=\"70%\"><input name=\"yourname\" type=\"text\" size=\"30\" value=\"".stripslashes($yourname)."\" /></td>\n");
Echo("</tr>\n");
Echo("<tr>\n");
Echo("<td width=\"30%\">Your Email:</td>\n");
Echo("<td width=\"70%\"><input name=\"youremail\" type=\"text\" size=\"30\" value=\"".stripslashes($youremail)."\" /></td>\n");
Echo("</tr>\n");
Echo("<tr>\n");
Echo("<td width=\"30%\" >Email Subject:</td>\n");
Echo("<td width=\"70%\"><input name=\"emailsubject\" type=\"text\" size=\"30\" value=\"".stripslashes($emailsubject)."\" /></td>\n");
Echo("</tr>\n");

If($allowattach) {
Echo("<tr>\n");
Echo("<td width=\"30%\">Attachment:</td>\n");
Echo("<td width=\"70%\"><input name=\"attachment\" type=\"file\" size=\"30\" /></td>\n");
Echo("</tr>\n");
}

Echo("<tr>\n");
Echo("<td colspan=\"2\">Your Message:<br />\n");
Echo("<textarea name=\"yourmessage\" rows=\"8\" cols=\"100%\">".stripslashes($yourmessage)."</textarea></td>\n");
Echo("</tr>\n");
Echo("<tr bgcolor=\"".$thead."\">\n");
Echo("<td colspan=\"2\" align=\"center\"><input name=\"domail\" type=\"submit\" value=\"".$submitvalue."\" /> <input type=\"reset\" value=\"".$resetvalue."\" /></td>\n");
Echo("</tr>\n");
Echo("</table>\n");
cp();
Echo("</body>\n");
Echo("</html>\n");
?>

lg
stephan
 
Wenn du 5 Dateien hochladen lassen willst, musst du auch 5 <input type="file"> im Formular platzieren.

P.S. bist du ein "Echo"-Fan, oder warum gibst du alles damit aus? Ist doch mächtig umständlich auf diese Art.
 
Das wird denk ich auf den meisten Servern nicht funktionieren, da Scripte normalerweise nach einer bestimmten Zeit abgebrochen werden.
 
Voggi hat gesagt.:
Das wird denk ich auf den meisten Servern nicht funktionieren, da Scripte normalerweise nach einer bestimmten Zeit abgebrochen werden.

Was hat das denn damit zu tun?
Zum Einen kann man das Zeitlimit höher setzen, zum Anderen dürfte es für das Skript nur Sekundenbruchteile an Unterschied ausmachen, ob man 1 oder 5 Dateien hochlädt.
 
Stimmt, man kann das Zeitlimit höher setzen. Aber im Normalfall nur, wenn man es auf seinem eigenen Server macht. Dein Hoster wird dich da nicht viel rumbasteln lassen. Bei den Sekundenbruchteilen muss ich dir leider wiedersprechen. Nehmen wir mal als Beispiel einen FTP Server. Du wirst höchstwahrscheinlich schon nen Unterschied merken, ob du jetzt eine Datei mit 5 MB hochlädst oder ob du fünf Dateien mit jeweils 5 MB hochlädst. Das Script kann im Grund auch nicht recht viel mehr machen, als die Dateien von deinem Rechner nehmen, bzw. zu kopieren und dann eben auf den Server zu legen. Und das dauert genau so lange, wie du auch mit einem FTP Programm brauchen würdest. D.h. Das Script muss auch so lange laufen. Und dann wird dir höchstwahrscheinlich die Standard Scriptlaufzeit nicht mehr ausreichen. Verbessert mich bitte, wenn es nicht stimmt.
 
Zuletzt bearbeitet:
Die Frage war aber nicht, wie man 25 MB hochlädt, sondern 5 Dateien....

zum Skript-Timeout...das kannst du direkt im Skript hochschrauben(sofern es der Hoster zulässt).
Mein Hoster z.B. erlaubt das....
 
naja, leider wurde meine frage immer noch nicht beantwortet. dadurch dass ich eine zweite file upload box hinzufüge, wird kein zweites attachment hinzugefügt. das zweite attachment geht dann logischer weise immer verloren...

grüße
stephan
 
Die Uploadfelder musst du entweder unterschiedlich benennen, oder es so schreiben:
Code:
 Echo("<td width=\"70%\"><input name=\"attachment[]\" type=\"file\" size=\"30\" /></td>\n");
.....dadurch erhältst du einen Array "attachment", in welchem alle hochgeladenen Dateien enthalten sind.
 
danke, schon kapiert. wenn das klappt wärs ja super einfach! ich versuchs gleich mal.vielen dank :)
 

Neue Beiträge

Zurück