I wrote the following script, but it seems like the tar file won't attach.
<?php
// Directory to compress and email
$directory = "/home/test/public_html/2.0.0/";
// Email from
$from = "backups@test.org";
// Email to
$to = "webmaster@test.org";
// File Name
$name = "Backup";
// Email Subject
$subject = "Site Backup";
// Email Message
$message = "main directory backup";
/* *************************
DO NOT EDIT BELOW THIS LINE
****************************/
// Add more details to the file name
$name .= " - ".date("n/d/Y @ g:i:s a");
// Create the command
$cmd = "tar -czvf ".$file.".tgz ".$directory;
// Create the tar
$exec = exec($cmd);
// Create the headers
$pathinfo = pathinfo("/");
$fileatt = $pathinfo['dirname'].$name;
$fileatt_type = "application/octet-stream"; // File Type
$headers = "From: ".$from;
// Read the file
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Write out the headers
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// Email the tar
mail($to,$subject,$message,$header) or die("Cannot email backup!");
?>
What did I do wrong?