No answer, but I’ve advanced a bit…
I’m using the found script below to try to send multiple attachments from a web server. The array of files varies but Im handling that okay. I can’t get past a couple of errors though and would appreciate any sharper eyes than mine. The errors appear to be path related and repeat for every attached file; one is posted after the script.
The path in the array works to load the files in a browser when the domain is switched with the DOCUMENT_ROOT.
[php]
#!/usr/bin/php
<?php
$files = array($_SERVER['DOCUMENT_ROOT'].'/images/classes/dc2010.jpg',$_SERVER['DOCUMENT_ROOT'].'/images/classes/dc2010.jpg');
$to = "
[email protected]";
$from = "
[email protected]";
$sub ="Testing for multiple attachment";
$msg = "Attachment mail testing";
$headers = "From: $from";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$msg = "This is a multi-part message in MIME format.\n\n" . "–{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $msg . "\n\n";
// attachments code starts
for($x=0;$x<count($files);$x++)
{
$msg .= "–{$mime_boundary}\n";
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
$msg .= "–{$mime_boundary}–\n";
$res = @mail($to, $sub, $msg, $headers);
if($res)
{
echo "
mail sent with attachments
";
}
else
{
echo "
error in processing email!
";
}
?>[/php]
Warning: fopen(/images/classes/dc2010.jpg): failed to open stream: No such file or directory in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 24
Warning: filesize(): stat failed for /images/classes/dc2010.jpg in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 25
Warning: fread() expects parameter 1 to be resource, boolean given in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 25
Warning: fclose() expects parameter 1 to be resource, boolean given in /private/var/folders/cO/cOJR83ytEkeFACn7Oaltu++++TM/-Tmp-/TemporaryItems/pn.2011.08.25.14.24.10.400.php on line 26