如何发送php生成的网站备份到电子邮件,而不是下载到系统

igsr9ssn  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(235)

我有这个php代码

.....................

        $query = "SELECT * FROM $table";
        $result = mysqli_query($conn, $query);

  ......

        $sqlScript .= "\n"; 
    }
    ?>

    <?php
    if(!empty($sqlScript))
    {
        // Save the SQL script to a backup file
        $backup_file_name = $database_name . '_backup_' . time() . '.sql';
        $fileHandler = fopen($backup_file_name, 'w+');
        $number_of_lines = fwrite($fileHandler, $sqlScript);
        fclose($fileHandler); 

        // Download the SQL backup file to the browser
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . basename($backup_file_name));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($backup_file_name));
        ob_clean();
        flush();
        readfile($backup_file_name);
        exec('rm ' . $backup_file_name); 
    }

这个php代码生成一个数据库备份文件并保存到设备,请我想把文件发送到电子邮件,而不是假设这是我的电子邮件句柄。

$email = \Config\Services::email();
       $email->setFrom('', '');
       $email->setTo("$email_send");
       $email->setSubject('Today backup');
       $email->setMessage("$body");
       $email->send();

拜托,我需要帮助

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题