欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 使用PHP备份MySQL和网站发送到邮箱的方法。 代码: 1 #!/usr/local/bin/php.cli 2 ?php 3 require_once './lib/swift_required.php'; 4 //MySQL 5 $mysql_dbname = "db"; 6 $mysql_user = "user"; 7
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
使用PHP备份MySQL和网站发送到邮箱的方法。
代码:
1 #!/usr/local/bin/php.cli
2
3 require_once './lib/swift_required.php';
4 //MySQL
5 $mysql_dbname = "db";
6 $mysql_user = "user";
7 $mysql_pass = "pass";
8 $mysql_file = "./xxx.sql";
9 $mysql_charset = "utf8";
10 system("mysqldump --default-character-set=$mysql_charset --opt -u$mysql_user -p$mysql_pass $mysql_dbname > $mysql_file");
11 //Backup WWW File
12 $www_path = "/www/";
13 @$final_file = "./xxx_com_".date("Y_m_d")。".zip";
14 system("zip -r -q $final_file $www_path $mysql_file");
15 //E-Mail
16 @$mail_title = "Backup for Coder4.com ".date("Y_m_d");
17 $mail_sender = "xxx_send@vip.qq.com";
18 $mail_recver = "xxx_recv@vip.qq.com";
19 $mail_body = "See attachments";
20 $mail_file = $final_file;
21 $sendmail_cmd = "/usr/sbin/sendmail -bs";
22 //Create E-Mail
23 $message = Swift_Message::newInstance();
24 $message->setSubject($mail_title);
25 $message->setFrom(array($mail_sender));
26 $message->setTo(array($mail_recver));
27 $message->setBody($mail_body);
28 $message->attach(Swift_Attachment::fromPath($mail_file));
29 //echo $message->toString();
30 //Send E-Mail
31 $transport = Swift_SendmailTransport::newInstance($sendmail_cmd);
32 $mailer = Swift_Mailer::newInstance($transport);
33 $result = $mailer->send($message);
34 //Delete
35 unlink($final_file);
36 unlink($mysql_file);
37 //End
38 echo "All backup success."
39 ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.