Got a new laptop recently and hadn't set up php and nginx in a long time went looking for a simple setup and thanks to TechTuts they had just what the doctor ordered.
Saturday, April 15, 2017
Tuesday, July 6, 2010
Send MySQL Backup thru Google Apps Email using PHP
This post combines items that were gathered from a few sites. The problem we were trying to solve is emailing a MySQL database backup using PHP PEAR through Google Apps. This script could also be easily modified to send through gmail. The file includes some hints and links to assist you whenever/wherever possible. Thank you Peter for providing the starting point for this script.
// enhanced from original provided @ http://www.theblog.ca/mysql-email-backup
// install the following pear modules
// pear install mail_mime
// pear install mail
// pear install net_smtp
// see this entry for more information about pear mail
// http://www.phpmaniac.net/wiki/index.php/Pear_Mail
// mysql database connection information
$dbhost = "localhost"; // usually localhost
$dbuser = "mydbuser";
$dbpass = "mydbpass";
$dbname = "mydbname";
// create the mysql backup file
$backupfile = $dbname . "_" . date("Y_m_d") . '.sql';
system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile");
// includes
include('Mail.php');
include('Mail/mime.php');
// smtp settings
$params["host"] = "smtp.gmail.com";
$params["port"] = "587";
$params["auth"] = true;
$params["username"] = "myusername@mydomain.com";
$params["password"] = "mypassword";
// email settings
$cr = "\n";
$recipients[] = "Recipient 1
$recipients[] = "Recipient 2
$sendfrom = "sender
$sendsubject = "Backup - MySQL - mydomain.com";
$text = "Database backup performed on " . date("m/d/Y @ H:i:s", time()) . $cr;
$text .= "File name: " . $backupfile;
// *************************************
// do not edit below this line
// *************************************
$message = new Mail_mime();
$message->setTXTBody($text);
$message->AddAttachment($backupfile);
$body = $message->get();
$extraheaders = array("From"=>$sendfrom, "Subject"=>$sendsubject);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("smtp", $params);
$mail->send($recipients, $headers, $body);
// Delete the file from your server
unlink($backupfile);
?>
Posted by
Joseph
at
8:54 AM
0
comments
Sunday, September 30, 2007
PHP Based SMTP Script with TLS Support
After some searching on the web I found a quick and easy to implement script that has support for TLS which is required for all Google SMTP (Outbound) email. Their documentation is thorough and gave me everything I needed to email without spending hours playing around with things.
XPertMailer - Advanced PHP Mail Engine
Posted by
Joseph
at
11:35 AM
0
comments
Labels: php