使用PHP备份MySQL和网站发送到邮箱 使用PHP备份MySQL和网站发送到邮箱实例代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

使用PHP备份MySQL和网站发送到邮箱 使用PHP备份MySQL和网站发送到邮箱实例代码

  2021-03-19 我要评论
想了解使用PHP备份MySQL和网站发送到邮箱实例代码的相关内容吗,在本文为您仔细讲解使用PHP备份MySQL和网站发送到邮箱的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:备份MySQL,网站发送到邮箱,php,下面大家一起来学习吧。

复制代码 代码如下:

#!/usr/local/bin/php.cli
<?php
require_once './lib/swift_required.php';

//MySQL
$mysql_dbname = "db";
$mysql_user = "user";
$mysql_pass = "pass";
$mysql_file = "./xxx.sql";
$mysql_charset = "utf8";
system("mysqldump --default-character-set=$mysql_charset --opt -u$mysql_user -p$mysql_pass $mysql_dbname > $mysql_file");

//Backup WWW File
$www_path = "../www/";
@$final_file = "./xxx_com_".date("Y_m_d").".zip";
system("zip -r -q $final_file $www_path $mysql_file");

//E-Mail
@$mail_title = "Backup for Coder4.com ".date("Y_m_d");
$mail_sender = "xxx_send@vip.qq.com";
$mail_recver = "xxx_recv@vip.qq.com";
$mail_body = "See attachments";
$mail_file = $final_file;
$sendmail_cmd = "/usr/sbin/sendmail -bs";

//Create E-Mail
$message = Swift_Message::newInstance();
$message->setSubject($mail_title);
$message->setFrom(array($mail_sender));
$message->setTo(array($mail_recver));
$message->setBody($mail_body);
$message->attach(Swift_Attachment::fromPath($mail_file));
//echo $message->toString();

//Send E-Mail
$transport = Swift_SendmailTransport::newInstance($sendmail_cmd);
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);

//Delete
unlink($final_file);
unlink($mysql_file);

//End
echo "All backup success."
?>

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们