Re: mail() - how to attach file to the message???
| From: | Chris Hayes | Date: | Wed, 09 Jul 2003 11:41:05 +0000 |
| Subject: | Re: mail() - how to attach file to the message??? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-154526@lists.php.net to get a copy of this message | ||
this worked for me but i did some editing and censoring oso maybe a tiny bug got in.
///SETUP strings
$subject='hi there, this is not a Viagra business proposal, ';
$mailto = 'xxx@ivm.vu.nl,xxx@sense.nl';// for multiple recipients, use comma 'x@x.x,y@y.y,z@z.z'
$From = '"Your website'" <yourmail@mail.org>'; // gets shown as mail sender. can be anything.
$message = "\nThis is a backup created by a script on your site. \nThe location of the script is ".__FILE__.'.';
$filedata = getyourcontentsomehow();
//create a filename for the email. the date and time at the start of the filename make it easy to sort it.
$filename = date("Y_m_d__H_i").'anytext'.".sql";
//prepare mail body
$filedata = chunk_split(base64_encode($filedata));
$type = "application/octet-stream";
$encoding = "base64";
mt_srand((double)microtime()*1000000);
$boundary = '--b'.md5(uniqid(mt_rand())) . getmypid(); //as long as it starts with -- it should work
$mailbody = "From: Your website script\n"
."MIME-Version: 1.0\n"
."Content-Type: multipart/mixed; boundary=\"$boundary\"\n\n"
."This is a MIME encoded message. \n\n"
."--$boundary\n"
."Content-Type: text/plain\n";
."Content-Transfer-Encoding: 8bit\n\n"
.$message . "\n\n\n--$boundary";
$data = "Content-Type: $type"."; name = \"$filename\"\n"
."Content-Transfer-Encoding: $encoding"
."\n\n$filedata\n";
$mailbody .= "\n$data\n--$boundary"
."--\n";
//send mail
mail($mailto, $subject , ' ', $mailbody) or die ('Could not send email!');