Jump to content

How to add a carbon copy into this database sender php script.


douza

Recommended Posts

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

}

 

?>

 

---------------------------------------------------------------------------

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

Archived

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

×
×
  • 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.