Jak wysłać maila z wieloma załącznikami? Podaję script, który wysyła jeden załącznik:
formularz.php
<script language="javascript">
function sprawdz() {
form1.message.value = form1.message.value + "\n" + form1.zaplata.value + form1.format.value + form1.papier.value;
form1.submit();
}
</script>
<form name="form1" method="post" action="sendmail.php" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>E-mail</td><td><input type="text" name="from">
<input name="subject" type="hidden" id="subject" value="Zamówienie odbitek cyfrowych">
<input name="sendto" type="hidden" id="sendto" value="[email protected]"></td></tr>
<tr>
<td>Adres domowy</td><td><textarea name="message" wrap="VIRTUAL"></textarea></td></tr>
<tr>
<td colspan="2">Sposób zapłaty
<select name="zaplata" id="zaplata">
<option value="Przedplata" selected>Przedpłata na konto (5 zł)</option>
<option value="Przy odbiorze">Przy odbiorze (10 zł)</option>
</select></td>
</tr>
<tr>
<td colspan="2">Format
<select name="format" id="format">
<option value="9x13" selected>9x13 (0.79 PLN)</option>
<option value="10x15">10x15 (0.99 PLN)</option>
<option value="13x18">13x18 (1.50 PLN)</option>
<option value="15x21">15x21 (2.50 PLN)</option>
</select></td>
</tr>
<tr>
<td colspan="2">Papier
<select name="papier" id="papier">
<option value="Blysk" selected>Błyszcz?cy</option>
<option value="Mat">Matowy</option>
</select></td>
</tr>
<tr>
<td colspan="2">Zdjęcie 1
<input type="file" name="filename"></td>
</tr>
<tr>
<td colspan="2">Zdjęcie 2
<input type="file" name="filename2"></td>
</tr>
<tr>
<td colspan="2"><input type="button" name="Submit" value="Realizuję zamówienie" onClick="sprawdz()"></td>
</tr>
</table>
</form>
sendmail.php
<?php
$boundary = "-->===_54654747_===<---->>4255==_";
$head = "From: $from\n";
$head = $head . "Reply-To: $replyto\n";
$head = $head . "X-Mailer: PHP\n";
$head = $head . "X-Sender: $from\n";
$head = $head . "MIME-version: 1.0\n";
$head = $head . "Content-type: multipart/mixed; ";
$head = $head . "boundary=\"$boundary\"\n";
$head = $head . "Content-transfer-encoding: 7BIT\n";
$head = $head . "X-attachments: $filename_name;\n\n";
$mesg = "--" . $boundary . "\n";
$mesg = $mesg . "Content-Type: text/plain; charset=\"us-ascii\"\n\n";
$mesg = $mesg . $message . "\n";
$mesg = $mesg . "--" . $boundary . "\n";
$mesg = $mesg . "Content-type: " . $filename_type . "; name=\"$filename_name\";\n";
$mesg = $mesg . "Content-Transfer-Encoding: base64\n";
$mesg = $mesg . "Content-disposition: attachment; filename= \"$filename_name\"\n\n";
$mesg = $mesg . fileopenanddecode($filename) . "\n";
$mesg = $mesg . "--" . $boundary . "-- \n";
function fileopenanddecode($file) {
if (is_readable($file)) {
$fd = fopen($file, "r");
$plik = fread($fd, filesize($file));
$encoded = chunk_split(base64_encode($plik));
fclose($fd);
}
return $encoded;
}
mail($sendto, $subject, $mesg, $head);
?>