Currently i'm learning php and doing some researches in mail() function.
The thing is whatever i try to do i can't send multiple files without some issues:
Here is processor code (Works with single attachmenets):
- Code: Select all
global $data;
// File Attributes
$fileatt = $_FILES['e_files']['tmp_name'];
$fileatt_type = $_FILES['e_files']['type'];
$fileatt_name = $_FILES['e_files']['name'];
// Start
$headers = "From: ".$data['mail'];
// Boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Headers
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Base message
$message ="This is a multi-part message in MIME format.\n\n";
$message.="--{$mime_boundary}\n";
$message.="Content-Type: text/plain; charset=\"utf-8\"\n";
$message.="Content-Transfer-Encoding: 7bit\n\n";
$message.="From: ".$data['mail']."\n";
$message.="name: ".$data['name']."\n";
$message.="tel: ".$data['last']."\n";
$message.="text: \n".$data['text']."\n\n";
// File Uploading
if(count($_FILES['e_files'])) {
foreach ($_FILES['e_files'] as $filez) {
if (is_uploaded_file($filez)) {
$file = fopen($filez,'rb');
$datas = fread($file,filesize($filez));
fclose($file);
$datas = chunk_split(base64_encode($datas));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$datas . "\n\n" .
"--{$mime_boundary}--\n";
}
}
}
}
And form action:
- Code: Select all
<form id="myForm" action="send.php" method="post" name="myForm" enctype="multipart/form-data">
<table width="360" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><span>File</span></td>
<td valign="top" align="left"><input type="file" name="e_files" id="e_files" /></td>
<tr>
</table>
</form>
Definitely doing something wrong.The question is how to send multiple attachments?
Thank you for your attention!

