PDA

View Full Version : Help Needed w/ZIP Mailing via mail()


SaintDog
07-11-2006, 09:46 PM
Below is the function I currently have for mailing, however the attachment isn't being attached. The location of the attachment is correct, however the function doesn't seem to attach it and mail it.

Any help would be greatly appreciated



function mailpackage ($email, $filename, $subject, $body) {
global $emailconfig;

$fromemail = $emailconfig['fromemail'];
$fromname = $emailconfig['fromname'];
$realfilename = $emailconfig['secretfolder'].'/'.$filename;
$mime_boundary = '==Multipart_Boundary_x'.md5(time()).'x';
$crlf = "\r\n";

$fp = fopen($realfilename,'rb');
$filedata = fread($fp, filesize($realfilename));
fclose($fp);
$headers = 'From: '.$fromname.' <'.$fromemail.'>'.$crlf.
'MIME-Version: 1.0'.$crlf.
'X-Mailer: PHP 4.x'.$crlf.
'X-Priority: 3'.$crlf.
'Content-Type: multipart/mixed;'.$crlf.
' boundary="'.$mime_boundary.'"';

$message = 'This is a multi-part message in MIME format.'.$crlf.$crlf.
'--'.$mime_boundary.$crlf.
'Content-Type: text/plain; charset="iso-8859-1"'.$crlf.
'Content-Transfer-Encoding: 7bit'.$crlf.$crlf.
str_replace($mime_boundary, '', $body).

$crlf.$crlf.'--'.$mime_boundary.$crlf.
'Content-Type: application/x-zip;'.$crlf.
' name="'.$filename.'"'.$crlf.
'Content-Disposition: attachment;'.$crlf.
' filename="'.$filename.'"'.$crlf.
'Content-Transfer-Encoding: base64'.$crlf.$crlf.

$crlf.'--'.$mime_boundary.'--'.$crlf;

mail($email, $subject, $message, $headers);
}

Chris Graham
07-14-2006, 07:01 PM
No it wouldn't, because it reads in the data and doesn't do anything with it ;) ($filedata isn't used).

Try adding:

$filedata.

after:

'Content-Transfer-Encoding: base64'.$crlf.$crlf.

SaintDog
07-14-2006, 07:10 PM
Nothing was specifically added to the e-mail nor was the zip attached. I do appreciate the help, however. I've been trying to get this to work for about 2 weeks now :).