There is a PHP class someone wrote called mime_mail that makes this easy.
The resulting code using this class is something like:
// create new mime_mail object instance
$mail = new mime_mail;
// set all data slots
$mail-from= [EMAIL PROTECTED];
$mail-to = [EMAIL PROTECTED];
$mail-subject = here's that file;
$mail-body= here's that file;
// read the file from disk
$fd = fopen($file_location, r);
$data = fread($fd, filesize($file_location));
fclose($fd);
// append the attachment
$mail-add_attachment($data, $file_name, $file_mime_type);
// send e-mail
$mail-send();
Look in phpclasses.upperdesign.com or search in Google.
-Ben
-Original Message-
From: Tym Rehm [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 09, 2001 12:18 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] sending attachments via mail(), possible?
You have to open the file and encode it.
Check out this:
html
head
titleFitnessQuest FTP user request form - results/title
/head
body
?php
$date = exec(date);
$border=--==_856811060==_;
/* Define the attachment and encode it base64 */
$filename=/var/www/sf/Ftp_User_Info.doc;
$fd = fopen($filename, r);
$contents = fread($fd, filesize($filename));
$encoded=chunk_split(base64_encode($contents));
fclose($fd);
/* Trim white spaces */
$request_by = trim($request_by);
$email = trim($email);
$company = trim($company);
/* testing if form is filled out */
if (empty($email) )
{
print h1FAILED!/h1;
print pThis form can't be sent! You did not fill the form out
bcompletely!/bbrThe email address is missing!br;
print brbrPlease click the bback/b button and fill in the email
addressbr;
print Thank you;
return;
}
if (empty($dr_ret) )
{
print h1FAILED!/h1;
print pThis form can't be sent! You did not fill the form out
bcompletely!/bbrThe system is not selected!br;
print brbrPlease click the bback/b button and select a system (DR
or Retail)br;
print Thank you;
return;
}
#/* recipients */
$recipient = $email;
#/* subject */
$subject = FitnessQuest FTP account form;
#/* message */
$message .= --$border\n;
$message .= Content-Type: text/plain; charset=us-ascii\n\n;
$message .= Attached is a FTP account access form. The form is in Microsoft
Word 97 format, please fill it out completely\n;
$message .= and email it back to [EMAIL PROTECTED] After a completed
form has been recieved your FTP account will be\n;
$message .= created. It will take approximately two working days to
complete your FTP account. You will recieve an email with\n;
$message .= username, password, and ftp server name. If you have questions,
email [EMAIL PROTECTED] or call your account\n;
$message .= representative. Thank you\n\n;
$message .= \n--$border\n;
$message .= Content-Type: application/msword; name=\Ftp\ User\
Info.doc\\n;
$message .= Content-Transfer-Encoding: base64\n;
$message .= Content-Disposition: attachment; filename=\Ftp\ User\
Info.doc\\n;
$message .= \n;
$message .= $encoded;
#$message .= --$border\n;
/* Header infomation */
$headers .= From: FTP Accounts [EMAIL PROTECTED]\n;
$headers .= X-Sender: [EMAIL PROTECTED]\n;
$headers .= Mime-Version: 1.0\n;
$headers .= Content-Type: multipart/mixed; boundary=\$border\\n;
#/* and now mail it */
mail($recipient, $subject, $message, $headers);
print h1Notices Sent/h1;
print h2pEmailed out!br/h2;
print pMail Sent to $recipientp;
/* Send notices to the distribution list */
/* Read Distribution list from text file */
$dlist = file(/var/www/sf/dlist);
$line = explode( ,, $dlist[0]);
array_push ($line, $request_by);
$dnumber = count($line);
if ($dnumber == 0)
{
print The list is emptyp;
}
for ($i=0; $i$dnumber; $i++)
{
# print $line[$i]br;
$line[$i] = trim($line[$i]);
/* Clear Notices var */
unset ($not_mess);
unset ($not_headers);
unset ($not_sub);
/* Notice Email Message */
$not_mess .= --$border\n;
$not_mess .= Content-Type: text/plain; charset=us-ascii\n\n;
$not_mess .= An FTP access form was emailed to $email.\n;
$not_mess .= Company name: $company\n;
$not_mess .= $company will be a $dr_ret customer\n\n\n\n;
$not_mess .= The request form was completed by $request_by on
$date.\n\n;
# $not_mess .= \n--$border\n;
/* Notice Subject */
$not_sub .= FTP user setup notice;
/* Notice Headers */
$not_headers .= From: FTP Accounts [EMAIL PROTECTED]\n;
$not_headers .= X-Sender: [EMAIL PROTECTED]\n;
$not_headers .= Mime-Version: 1.0\n;
$not_headers .= Content-Type: multipart/mixed; boundary=\$border\\n;
/* Send Notice email to distribution list */
/* Diag testing */
# print |$line[$i]|br;
# print |$not_sub|br;
# print |$not_mess|br;
# print |$not_headers|brp;
mail($line[$i], $not_sub, $not_mess, $not_headers);
}
?
/body/html
- Original Message -
From: Christian Dechery [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, May 09, 2001 3:10 PM
Subject: [PHP] sending attachments via mail(), possible?
Is it possible to send attachments via mail() function?
I tried