Ahoj, potřeboval bych radu jak upravit PHP, kde mi skript odesílá jednu přílohu, aby odesilal více příloh na email.
Fórum › PHP
PHP - Odeslání formuláře s více přílohama E-mail, Poradit

To KIIV : pokud mi poradis budu rad.
mam to takto:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Odeslání přílohy</title>
<meta http-equiv=Content-Type content="text/html; charset=windows-1250">
<meta http-equiv="Content-Language" content="cs">
</head>
<body style="background-color:white; color:black">
<?php
///////////////////// MAXIMÁLNÍ VELIKOST PŘÍLOHY. UPRAVTE TÉŽ V index.html
$max_att = 50000;
/////////////////////// ///////////////////
$to = @.cz';
//////////////////////////////////////////////////////////////////
$charset = 'windows-1250';
if(!isset($_POST['submitter'])) exit('<h1>Error 1</h1>');
$subject = 'Priloha z webu';
$from = $_POST['Odesilatel'];
$message .= 'Odesláno ze stránky: ' . $_SERVER['HTTP_REFERER'] . "\r\n";
while (list($name, $value) = each($_POST)) {
if ($name == 'MAX_FILE_SIZE' || $name == 'charset' || $name == 'submitter') {
}
elseif (gettype($value) == 'array') { // TAG SELECT MULTIPLE
$cnt = count($value);
for ($i=0; $i < $cnt; $i++) {
$message .= "$name: $value[$i]r\\n";
}
}
else { // OSTATNÍ ELEMENTY
$message .= "$name: $value\r\n";
}
}
$valid = 1;
$file_size = $_FILES['fileatt']['size'];
$file_name = $_FILES['fileatt']['name'];
$file_type = $_FILES['fileatt']['type'];
if ($file_size > 0) $att_present = true;
$message .= "VELIKOST PŘÍLOHY: $file_size bytes\r\n\n";
if($att_present) {
if($file_size > $max_att) {
$valid = 0;
$err_msg .= "<p>Příloha je větší nežli povolených $max_att bajtů";
}
if (
$file_type != 'text/plain' // TXT
&& $file_type != 'text/html' // HTM
&& $file_type != 'text/html' // HTML
&& $file_type != 'image/gif' // GIF
&& $file_type != 'image/jpeg' // JPG JPEG
&& $file_type != 'image/pjpeg' // JPG JPEG
&& $file_type != 'image/png' // PNG
&& $file_type != 'image/x-icon' // ICO
&& $file_type != 'application/msword' // DOC
&& $file_type != 'application/excel' // XLS
&& $file_type != 'application/rtf' // RTF
&& $file_type != 'application/octet-stream' // DOC
&& $file_type != 'application/x-zip-compressed' // ZIP
&& $file_type != 'application/pdf'
) { // PDF
$valid = 0;
$err_msg .= "<p>Skript nepodporuje tento typ souboru $file_type";
}
$dots = substr_count($file_name,'.');
if($dots != 1) {
$valid = 0;
$err_msg .= "<p>Příloha má nepovolený počet extenzí $dots";
}
$extension = strtolower(strstr($file_name,'.'));
if (
$extension != ".txt"
&& $extension != ".htm"
&& $extension != ".html"
&& $extension != ".gif"
&& $extension != ".jpg"
&& $extension != ".jpeg"
&& $extension != ".png"
&& $extension != ".ico"
&& $extension != ".doc"
&& $extension != ".xls"
&& $extension != ".rtf"
&& $extension != ".zip"
&& $extension != ".pdf"
) {
$valid = 0;
$err_msg .= "<p>Skript nepodporuje extenzi $extension";
}
$p = strlen($extension);
if($p != 4 && $p != 5) {
$valid = 0;
$err_msg .= "<p>Příloha má neplatnou délku extenze $p";
}
if($valid == 1){
$fileatt = $_FILES['fileatt']['tmp_name'];
$headers = "From: $from";
if(is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=$charset\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_type};\n" .
" name=\"{$file_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$message = StripSlashes($message);
$sent = @mail($to, $subject, $message, $headers);
if($sent) echo "<h1>Formulář byl úspěšně odeslán</h1>";
else echo "<h1>Formulář se nezdařilo odeslat</h1>";
}
if($valid!==1) {
echo "<h2>Chyba...</h2>$err_msg";
echo "<p>Klikněte na Zpět a zkuste znovu";
}
}
else { // není příloha
$message = StripSlashes($message);
$sent = @mail($to, $subject, $message, $headers);
if($sent) echo "<h1>Formulář byl úspěšně odeslán</h1>";
else echo "<h1>Formulář se nezdařilo odeslat</h1>";
}
?>
</body>
</html>


do FORM pridat par inputu na vyber souboru (input type="file") - aby se dalo vic taky vybrat
a pak zpracovavat jednotlive soubory a pridavat do mailu podobne jako je to u samostatneho souboru
neco jako <input type="file" name="fileatt[]" />
a pak to prochazet cyklem


Tady řešíme dílčí problémy, ne celý projekt. A už vůbec ne za tebe. LOCK



Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
PHP - odeslání formuláře (mezera) — založil diabolus99
PHP redirect po odeslani formulare — založil e-sparco
Simulace odeslání souboru z formuláře scriptem php — založil neumetel
Odeslaní dat z PHP formuláře do SQL databáze — založil Hanis Novák
[E-mail] - odeslání s přílohou — založil Gibon
Moderátoři diskuze