这篇文章主要为大家详细介绍了php 发送mysql数据自动备份的邮件实现方法,具有一定的参考价值,可以用来参考一下。
为大家讲述一下 php给自己发送自动备份的mysql数据表邮件,感兴趣的小伙伴,下面一起跟随512笔记的小编罗X来看看吧。
经测试代码如下:
/**
* 自动备份的mysql数据表邮件发送
*
* @param
* @arrange (512.笔记) www.512pic.com
**/
$dbhost = "yourhost"; // usually localhost
$dbuser = "yourusername";
$dbpass = "yourpassword";
$dbname = "yourdb";
$sendto = "Webmaster ";
$sendfrom = "Automated Backup ";
$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);
/*** 代码来自512笔记(www.512pic.com) ***/
注:关于php 发送mysql数据自动备份的邮件实现方法的内容就先介绍到这里,更多相关文章的可以留意512笔记的其他信息。
关键词:邮件