|
Posted by Manfred Kooistra on 01/13/07 12:43
Thank you so far.
To make this more concrete:
I am trying to send a variable number of attachments with PEAR::Mail.
With a fixed number of attachments (example with 1 file), the relevant
part of the code was this:
$mime->addAttachment($file, "image/$type_of_file",
$_FILES['upfile_0']['name']);
Now, with an unknown number of files, I changed that part of the code
to (exactly as in my script):
$i = 0;
foreach($_POST_DATA as $key => $value){
if(preg_match("/^upfile_/i", $key)){
$uploaded_file_name = $value;
$uploaded_file_path = $_POST_DATA['upload_dir'] .
$uploaded_file_name;
if(is_file($uploaded_file_path)){
preg_match('/(\.\w+)$/', $uploaded_file_name, $match);
$typ = substr($match[1], 1);
$handle = fopen($uploaded_file_path, 'r');
$file = fread($handle, filesize($uploaded_file_path));
$mime->addAttachment($file, "image/$typ", $uploaded_file_name);
fclose($handle);
$i++;
}
}
}
$_POST_DATA is stuff processed through a Perl script. Files are named
upfile_0, upfile_1 etc. The data is all there, I checked it. I can even
output $file to the screen, but $mime->addAttachment seems not do do
anything, because the emails arrive without attachment (all other
content is okay, since the rest of the [rather very long, so not posted
here] script is unchanged).
It seems to me that somehow the foreach and the -> don't work well
together, because I have the same foreach loop for the email content,
where $text .= $sometextfragment; works fine.
[Back to original message]
|