php 发送mysql数据自动备份的邮件实现方法

前端之家收集整理的这篇文章主要介绍了php 发送mysql数据自动备份的邮件实现方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为大家讲述一下 PHP给自己发送自动备份MysqL数据表邮件,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

<?
/**
 * 自动备份MysqL数据表邮件发送
 *
 * @param 
 * @arrange (512.笔记) jb51.cc
 **/
$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);


/***   代码来自编程之家 jb51.cc(jb51.cc)   ***/
原文链接:https://www.f2er.com/php/528835.html

猜你在找的PHP相关文章