Exemple #1
0
// Create the mysql backup file
// edit this section
$dbhost = "localhost";
// usually localhost
$dbuser = "******";
//enter your database username here
$dbpass = "******";
//enter your database password here
$dbname = "cityhow-pagodap";
// enter your database name here
$sendto = "Send To <*****@*****.**>";
$sendfrom = "Send From <*****@*****.**>";
$sendsubject = "Daily Database Backup";
$bodyofemail = "Here is the daily backup of my database.";
// don't need to edit below this section
$backupfile = $dbname . date("Y-m-d") . '.sql.gz';
system("mysqldump -h {$dbhost} -u {$dbuser} --password={$dbpass} {$dbname} | gzip > {$backupfile}");
// Mail the file
include 'Mail.php';
include 'Mail/mime.php';
$message = new Mail_mime();
$text = "{$bodyofemail}";
$message->setTXTBody($text);
$message->AddAttachment($backupfile);
$body = $message->get();
$extraheaders = array("From" => "{$sendfrom}", "Subject" => "{$sendsubject}");
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send("{$sendto}", $headers, $body);
// Delete the file from your server
unlink($backupfile);