<?php
require_once('class.phpmailer.php');


$title="一线印象";//网站名
$host="112.121.172.43";//mysql地址
$user="a0818201251";//mysql用户名
$password="12969197";//mysql密码
$dbname="a0818201251";//mysql名

//设置说明：将以上项填写正确后到下面修改邮箱信息。确认所有信息无误后到http://yxrw.cf注册帐号并在四号系统增加本页面。

mysql_connect($host,$user,$password);
mysql_select_db($dbname);
$mysql= "set names utf8;";
mysql_query($mysql);
$q1=mysql_query("show tables");
while($t=mysql_fetch_array($q1)){
$table=$t[0];
$q2=mysql_query("show create table `$table`");
$sql=mysql_fetch_array($q2);
$mysql.=$sql['Create Table'].";\n";
$q3=mysql_query("select * from `$table`");
while($data=mysql_fetch_assoc($q3)){
$keys=array_keys($data);
$keys=array_map('addslashes',$keys);
$keys=join('`,`',$keys);
$keys="`".$keys."`";
$vals=array_values($data);
$vals=array_map('addslashes',$vals);
$vals=join("','",$vals);
$vals="'".$vals."'";
$mysql.="insert into `$table`($keys) values($vals);\n";
}
$mysql.="\n";
}
$filename="bei/".$dbname.date('Ymj').".sql";
$fp = fopen($filename,'w');
fputs($fp,$mysql);
fclose($fp);
echo "
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>备份</title>
</head>
<body>
<p>数据备份成功，生成备份文件：".$filename."</p>";
$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host = "smtp.qq.com"; //SMTP服务器 以qq邮箱为例子
$mail->Port = 25;  //邮件发送端口
$mail->SMTPAuth   = true;  //启用SMTP认证
$mail->CharSet  = "UTF-8"; //字符集
$mail->Encoding = "base64"; //编码方式
$mail->Username = "1546912750@qq.com";  //你的邮箱
$mail->Password = "13994642471";  //你的密码
$mail->Subject = $title.date('Ymj')."备份成功"; //邮件标题
$mail->From = "1546912750@qq.com";  //发件人地址（也就是你的邮箱）
$mail->FromName = "印象";  //发件人姓名
$address = "";//收件人email
$mail->AddAddress($address, "印象");//添加收件人（地址，昵称）
$mail->AddAttachment($filename,'备份文件.sql'); // 添加附件,并指定名称
$mail->IsHTML(true); //支持html格式内容
//$mail->AddEmbeddedImage("logo.jpg", "my-attach", "logo.jpg"); //设置邮件中的图片
$mail->Body = "<p>".$title.date('Ymj')."备份成功</p>"; //邮件主体内容
//发送
if(!$mail->Send()) {
  echo "<p>发送到邮箱错误：" . $mail->ErrorInfo."</p>";
} else {
  echo "<p>发送到邮箱成功</p>
</body>
</html>";
}
?>