Jump to content


Photo

sending gz file as an attachment


  • Please log in to reply
1 reply to this topic

#1 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 March 2006 - 04:24 PM

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);
                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);

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

#2 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 17 March 2006 - 09:50 AM

bump




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users