Jump to content

sending gz file as an attachment


kkroo

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:

[code]
‹
[/code]

pretty lame huh?

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

[code]
                $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);
                gzclose($gz);
                
                # 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
                $emailaddress="my@mail.com";
                # 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);
[/code]

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.