I would like to know the code about backup MySQL db to an email like if I click the button "send to my email" it will pop-up a modal (sb-admin bootstrap) saying, input your email. then it will go directly to that email.
1条回答 默认 最新
- doubi4617 2017-02-15 09:08关注
In order to do this first of all you will have to dump the database.
You can use the exec() function to execute an external command.
exec('mysqldump --user=... --password=... --host=... DB_NAME > /path/to/output/file.sql');
This will dump the Db. then you will have to attach this file to send mail.
you can use
phpmailer
to do thisTo use PHPMailer:
- Download the PHPMailer script from here: http://github.com/PHPMailer/PHPMailer
Extract the archive and copy the script's folder to a convenient place in your project.
Include the main script file -- require_once('path/to/file/class.phpmailer.php');
Now, sending emails with attachments goes from being insanely difficult to incredibly easy:
$email = new PHPMailer(); $email->From = 'you@example.com'; $email->FromName = 'Your Name'; $email->Subject = 'Message Subject'; $email->Body = $bodytext; $email->AddAddress( 'destinationaddress@example.com' ); $file_to_attach = 'PATH_OF_YOUR_FILE_HERE'; $email->AddAttachment( $file_to_attach , 'file.sql' ); return $email->Send();
解决 无用评论 打赏 举报
悬赏问题
- ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
- ¥15 unity连接Sqlserver
- ¥15 图中这种约束条件lingo该怎么表示出来
- ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
- ¥15 流式socket文件传输答疑
- ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
- ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
- ¥15 win10,这种情况怎么办
- ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
- ¥100 在连接内网VPN时,如何同时保持互联网连接