Jump to content

Zip email attachment


jrp91384

Recommended Posts

Hi,

 

I'm trying to figure out how to have my sql dump file gz-zipped prior to being sent via email. I don't know much about php and have not been able to figure it out after viewing many snippets online. If someone can steer me in the right direction I would really appreciate it. The following is the script I am using.

 

Thank you!

 

 

<?

 

//data.php is all of the connection info

require("data.php");

 

  $today    = date("m-d-Y");

 

  exec('mysqldump -u'.$User.' -p'.$Password.' '.$DBName.' > /tmp/dbDump-'.$today.'.sql');

 

//send MIME message with dump

 

$EmailBody  = implode("\n",file('/tmp/dbDump-'.$today.'.sql'));

   

//email body text   

$htmltext = "Your database backup file is attached. Please save it in a secure location.<br /><br />Thank you\n";

 

 

$text = "Mien Dumpenflugen\n";

 

//edit for each backup

$FromName = "XXXXX";

$from = "XXXXX";

$fromname = "XXXXX";

$subject = "db-dump $today";

$ToName = "XXXXX";

$ToEmail = "XXXXX";

 

 

//add From: header

$headers = "From: ".$from."\n";

 

//specify MIME version 1.0

$headers .= "MIME-Version: 1.0\n";

 

//unique boundary

$boundary = uniqid(MD5(time()));

 

 

//tell e-mail client this e-mail contains

//alternate versions

// use alt for test and multi for attachements

 

 

$headers .= "Content-Type: multipart/alternative" ."; boundary = $boundary\n\n";

 

//message to people with clients who don't

//understand MIME

$headers .= "This is a MIME encoded message. If you are seeing this, your mail program is not MIME compliant. Sorry\n\n";

 

//HTML version of message

$headers .= "--$boundary\n" ."Content-Type: text/html; charset=ISO-8859-1\n"."Content-Transfer-Encoding: base64\n"."Content-Disposition: inline\n\n";

$headers .= chunk_split(base64_encode($htmltext));

$headers .="--$boundary\n";

 

//plain text version of message

$headers .="--$boundary\n";

$headers .= "Content-Type: text/plain; charset=ISO-8859-1\n"."Content-Transfer-Encoding: 7bit\n"."Content-Disposition: inline\n";

$headers .= $text;

$headers .= "--$boundary\n";

 

$boundary2 = uniqid(MD5(time()));

$headers .= "Content-Type: multipart/mixed" ."; boundary = $boundary2\n\n";

 

//echo "<br><br>Boundry:<br> $boundary<br>$boundary2<br>end of boundry";

 

 

 

  $attach_path = "/tmp/dbDump-".$today.".sql";

  $attach = "dbDump-".$today.".sql";

  //attachment filename Data

 

    $headers .= "--$boundary2\n";

    $headers .= "Content-Type: text/richtext; "."name=\"".$attach."\"\n";

    $headers .= "Content-Transfer-Encoding: "."base64\n";

    $headers .= "Content-Disposition: attachment\n\n";

    $filedata = implode(file('/tmp/dbDump-'.$today.'.sql'));

    $headers .= chunk_split(base64_encode($filedata));

 

 

$headers .= "--$boundary2--\n";

 

$headers .= "--$boundary--\n";

//echo $headers;

//send message

mail($ToName." <".$ToEmail.">", $subject, "", $headers);

 

$ToEmail = "XXXXX";

mail($ToName." <".$ToEmail.">", $subject, "", $headers);

 

 

//cron output confirm email

echo "Cron Dump processed $today\n";

?>

Link to comment
https://forums.phpfreaks.com/topic/162799-zip-email-attachment/
Share on other sites

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.