Welcome to the Linux community forum and interact with 2 million technical staff to access how to back up MySQL using PHP and send the website to your mailbox. Code: 1 #! Usrlocalbinphp. cli2? Php3require_once.libswift_required.php; 4MySQL5 $ mysql_dbnamedb; 6 $ mysql_useruser; 7
Welcome to the Linux community forum, and interact with 2 million technical staff> go to the PHP backup MySQL and website sending method. Code: 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
Welcome to the Linux community forum and interact with 2 million technicians>
Use PHP to back up MySQL and send the website to your mailbox.
Code:
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 // email
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?>