<?php
/* Database */
$db = 'test';
$dbuser = 'root';
$dbpw = '';
$dbhost = 'localhost';
/* Email*/
$to = "test@gmx.de";
/* Misc */
$file = "config/backup_" . $db . ".sql.gz";
$message = "DB-Backup ".$file." von ".$dbhost." im Anhang.\n\n-- \n" . strip_tags($_SERVER["SERVER_SIGNATURE"]);
$subject = "DB-Backup ".$file;
$from = "MySQL-Backup<".$_SERVER["SERVER_ADMIN"].">";
/* Systemcall */
echo dirname(__FILE__)."<br>";
system("/usr/local/bin/mysqldump -u".$dbuser." -p".$dbpw." -h ".$dbhost." ".$db." | gzip > ".$file, $fp);
if ($fp==0) echo "Backup erfolgreich!"; else die("Backup konnte nicht erfolgreich erstellt werden!");
/* Prepare the email*/
$boundary = strtoupper(md5(uniqid(time())));
$mail_header = "From:".$from."\n";
$mail_header .= "MIME-Version: 1.0";
$mail_header .= "\nContent-Type: multipart/mixed; boundary=".$boundary;
$mail_header .= "\n\nThis is a multi-part message in MIME format -- Dies ist eine mehrteilige Nachricht im MIME-Format";
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
$mail_header .= "\n\n".$message;
$file_content = fread(fopen($file,"r"),filesize($file));
$file_content = chunk_split(base64_encode($file_content));
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: application/octetstream; name=\"".$file."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"".$file."\"";
$mail_header .= "\n\n".$file_content;
$mail_header .= "\n--".$boundary."--";
/* Send the email */
mail($to,$subject,"",$mail_header);
?>