这篇文章主要为大家详细介绍了php 发送mysql数据自动备份的邮件实现方法,具有一定的参考价值,可以用来参考一下。
为大家讲述一下 php给自己发送自动备份的mysql数据表邮件,感兴趣的小伙伴,下面一起跟随四海网的小编罗X来看看吧。
<?
/**
* 自动备份的mysql数据表邮件发送
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
$dbhost = "yourhost"; // usually localhost
$dbuser = "yourusername";
$dbpass = "yourpassword";
$dbname = "yourdb";
$sendto = "Webmaster <webmaster@yourdomain.com>";
$sendfrom = "Automated Backup <backup@yourdomain.com>";
$sendsubject = "Daily Mysql Backup";
$bodyofemail = "Here is the daily backup.";
// don't need to edit below this section
$backupfile = $dbname . date("Y-m-d") . '.sql';
system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $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);
/*** 代码来自四海网(www.q1010.com) ***/
本文来自:http://www.q1010.com/173/486-0.html
注:关于php 发送mysql数据自动备份的邮件实现方法的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:邮件
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。