Below is a script that I found to copy my database to a zipped file and then mail it to me. I get no error messages, the file shows up, but there's no data inside the file. This is my first time using mysqldump, but from what I've seen online, the line that does the dump looks fine. If anybody has any thoughts, that would be great!
(One thing that I'm not clear about, is how the script connects with the DB on my server...shouldn't it have some sort of server name connection??
Also, I can't imagine that this has anything to do with anything, but I'm using GoDaddy.com as my host)
include('/users/admin/database_configuration.php'); //where I keep my $dbusername, $dbpassword, $dbname
$datestamp = date("Y-m-d"); // Current date to append to filename of backup file in format of YYYY-MM-DD
/* CONFIGURE THE FOLLOWING VARIABLES TO MATCH YOUR SETUP */
$filename= "backup-$datestamp.sql.gz"; // The name (and optionally path) of the dump file
$to = "firstname.lastname@example.org"; // Email address to send dump file to
$from = "email@example.com"; // Email address message will show as coming from.
$subject = "MySQL backup file"; // Subject of email
$command = "mysqldump -u $dbusername --password=$dbpassword $dbname | gzip > $filename";
$result = passthru($command);
$attachmentname = array_pop(explode("/", $filename)); // If a path was included, strip it out for the attachment name
$message = "Compressed database backup file $attachmentname attached.";
$mime_boundary = "< <<:" . md5(time());
$data = chunk_split(base64_encode(implode("", file($filename))));
$headers = "From: $from\\r\
$headers .= "MIME-Version: 1.0\\r\
$headers .= "Content-type: multipart/mixed;\\r\
$headers .= " boundary=\\"".$mime_boundary."\\"\\r\
$content = "This is a multi-part message in MIME format.\\r\
$content.= "Content-Type: text/plain; charset=\\"iso-8859-1\\"\\r\
$content.= "Content-Transfer-Encoding: 7bit\\r\
$content.= "Content-Disposition: attachment;\\r\
$content.= "Content-Type: Application/Octet-Stream; name=\\"$attachmentname\\"\\r\
$content.= "Content-Transfer-Encoding: base64\\r\
$content.= "--" . $mime_boundary . "\\r\
mail($to, $subject, $content, $headers);
unlink($filename); //delete the backup file from the server
The code is working as it should, I've tested, it must be something in the include file or with the mail server.
I appreciate your testing the code for me. I wound up going a different route, using "Zend_Mail" --- super easy for me to add attachments. After doing so I found some posts saying that my host doesn't support mail() as is...so you're actually 100% correct: it WAS the server.