Jump to content


This topic is now archived and is closed to further replies.


sending gz file as an attachment

Recommended Posts

for the past hour, i have been trying multiple things to get this to work!

what it does is backs up my DB and saves it as a gzip, then it emails a gzip file to my email with a message saying Your database has been backed up successfully on (date).

at the current state, it doesn't show the email message, and the file is corrupted, this is the file's contents in the view message source:


pretty lame huh?

this is the part of the script that deals with the email and gzips:

                $file_name = 'phpbb_db_backup_' . date("d-m-Y_H-i", time()) . '.sql.gz';
                $gz = gzopen(''. $phpbb_root_path . 'backups/' . $file_name . '','w9');
                gzwrite($gz, $backup);
                # Compress DB for sending
                $backup_gz = gzcompress($backup);

                # Message body
                $body = "Your database has been backed up successfully on " .date("Y/m/d H:i:s") .".";
                # Is the OS Windows or Mac or Linux
                if (strtoupper(substr(PHP_OS,0,3)=='WIN')): $eol="\r\n"; elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')): $eol="\r"; else: $eol="\n"; endif;

                # To Email Address
                # Message Subject
                $emailsubject="Database Backup ".date("Y/m/d H:i:s");

                # Common Headers
                $headers .= 'From: ' . $board_config['sitename'] . ' <' . $board_config['board_email'] . '>'.$eol;
                $headers .= 'Reply-To: ' . $board_config['sitename'] . ' <' . $board_config['board_email'] . '>'.$eol;
                $headers .= 'Return-Path: ' . $board_config['sitename'] . ' <' . $board_config['board_email'] . '>'.$eol;    // these two to set reply address
                $headers .= "Message-ID: <".$now." noreply@".$_SERVER['SERVER_NAME'].">".$eol;
                $headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters
                # Boundry for marking the split & Multitype Headers
                $mime_boundary = md5(time());
                $headers .= 'MIME-Version: 1.0'.$eol;
                $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
                $msg = "";

                # Attachment
                $msg .= "--".$mime_boundary.$eol;
                $msg .= "Content-Type: application/x-gzip; name=\"".$file_name."\"".$eol;
                $msg .= "Content-Transfer-Encoding: base64".$eol;
                $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol;
                $msg .= $backup_gz.$eol.$eol;
                $msg .= "Content-Type: multipart/alternative".$eol;
                # Message
                $msg .= "--".$mime_boundary.$eol;
                $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
                $msg .= $body.$eol.$eol;
                # Finished
                $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.

                # SEND THE EMAIL

                mail($emailaddress, $emailsubject, $msg, $headers);

The file that the script puts in the directory is fine, but not the attachment. I don't want to do fread because that will waste time.

I would really apprecaite it if somebody points out the retarded mistake I am making here.

Thanks in advance

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.