douza Posted December 15, 2007 Share Posted December 15, 2007 Does anyone know how to add a second email i.e. carbon copy (cc) into this script I have had a few attempts but failed. Thanks Code below.. --------------------------------------------------------------- <?php $dbhost = ''; $dbuser = ''; $dbpass = ''; $dbname = ''; $use_gzip = "yes"; $remove_sql_file = "yes"; $remove_gzip_file = "no"; $savepath = ""; $send_email = "yes"; $to = ""; $from = ""; $senddate = date("j F Y"); $subject = "MySQL Database Backup - $senddate"; $message = "MySQL database has been backed up and is attached to this email"; $use_ftp = "yes"; $ftp_server = ""; $ftp_user_name = ""; $ftp_user_pass = ""; $ftp_path = "/"; $date = date("mdy-hia"); $filename = "$savepath/$dbname-$date.sql"; passthru("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname >$filename"); if($use_gzip=="yes"){ $zipline = "tar -czf ".$dbname."-".$date."_sql.tar.gz $dbname-$date.sql"; shell_exec($zipline); } if($remove_sql_file=="yes"){ exec("rm -r -f $filename"); } if($use_gzip=="yes"){ $filename2 = "$savepath/".$dbname."-".$date."_sql.tar.gz"; } else { $filename2 = "$savepath/$dbname-$date.sql"; } if($send_email == "yes" ){ $fileatt_type = filetype($filename2); $fileatt_name = "".$dbname."-".$date."_sql.tar.gz"; $headers = "From: $from"; $file = fopen($filename2,'rb'); $data = fread($file,filesize($filename2)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n" ."--{$mime_boundary}\n" ."Content-Type: text/plain; charset=\"iso-8859-1\"\n" ."Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $data = chunk_split(base64_encode($data)); $message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name=\"{$fileatt_name}\"\n" ."Content-Disposition: attachment;\n" ." filename=\"{$fileatt_name}\"\n" ."Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" ."--{$mime_boundary}--\n"; $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<h4><center>Database backup created and sent! File name $filename2</center></h4>"; } else { echo "<h4><center>Mail could not be sent. Sorry!</center></h4>"; } } if($use_ftp == "yes"){ $ftpconnect = "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2"; shell_exec($ftpconnect); echo "<h4><center>$filename2 Was created and uploaded to your FTP server!</center></h4>"; } if($remove_gzip_file=="yes"){ exec("rm -r -f $filename2"); } ?> --------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
themistral Posted December 15, 2007 Share Posted December 15, 2007 There are a quite a few sites that will explain this and give examples. Googling turned this one up - http://forums.hostmysite.com/about1171.html Quote Link to comment Share on other sites More sharing options...
douza Posted December 16, 2007 Author Share Posted December 16, 2007 Hi themistral, Thanks for that reply I have had a play around with the code and Ive managed to get a copy to a different addy. The only problem is now the from header wont work. I think I need the code below to have a ful stop after the ($headers =) so it reads ($headers .=) but that still wont work either. Also what does the line (\r\n) mean after the line like in the example you gave. $headers = "From: $from"; $headers = "CC: $cc"; Phil Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 16, 2007 Share Posted December 16, 2007 Use imap_mail Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.