Email problems solved and some improvements

Post your support requests/solutions for phpMySQLAutoBackup [website]
Seems to be staying... Lets see...
Seems to be staying... Lets see...
Posts: 2
Joined: Tue Jan 22, 2008 12:28 pm

Email problems solved and some improvements

Postby nicks » Tue Jan 22, 2008 1:47 pm

I have had problems recently with some users of a website I developed not getting emails sent to them by the website. There is no error returned to the sender and no bounced messages received back. The recipient doesn't receive anything either, not even an email flagged as SPAM. I solved this problem by making use of phpMailer ( a set of Open Source PHP classes, to send SMTP email.

I have had a similar problem in the past with phpMySQLAutoBackup and I was unable to solve it at the time and gave up on it. Solving the email problem with my own site got me thinking about phpMySQLAutoBackup again.

I have hacked phpmysqlautobackup_extras.php to make use of phpMailer to send SMTP emails. This has solved my own problem with emails not being received and also gives some potential improvements, e.g. the ability to change the sender and the capability to cc the email to another account.

You need to edit the xmail function in files/phpmysqlautobackup_extras.php and delete all the code in that function and insert the phpmailer code shown below:

Code: Select all

function xmail ($to_emailaddress,$from_emailaddress, $subject, $content, $file_name, $backup_type)
  // Modification to use phpMailer ( to send SMTP emails

  $phpmailer_hosthame = ""; // e.g. ""
  $phpmailer_host     = ""; // e.g. ""
  $phpmailer_port     = "25"; // Most likely "25"

  $phpmailer_username = ""; // e.g. ""
  $phpmailer_password = ""; // Your password

  $phpmailer_sender   = ""; // e.g. ""
  $phpmailer_from     = $phpmailer_sender;
  $phpmailer_fromname = ""; // Your name

  $phpmailer_to       = ""; // e.g. ""
  $phpmailer_toname   = ""; // Your name

  $phpmailer_cc       = ""; //  e.g. "" - Leave blank if you don't want to cc the email.
  $phpmailer_ccname   = ""; // Your name

  $phpmailer_subject  = "phpMySQLAutoBackup: " . $file_name;

  $phpmailer_htmlbody =
    "<b>BACKUP Successful...</b> <br /><br />\n\n"
    . "Please see attached for your zipped Backup file; $backup_type <br />\n"
    . "If this is the first backup then you should test it restores correctly to a test server. <br /><br />\n\n"
    . "phpMySQLAutoBackup is developed by <a href=''></a> <br /><br />\n\n"
    . "Have a good day now you have a backup of your MySQL db  ;-) <br /><br />\n\n"
    . "Please consider making a donation at: <br />\n"
    . "<a href=''></a> <br />\n"
    . "(any amount is gratefully received) <br />\n";

  $phpmailer_textbody =
    "BACKUP Successful... \n\n"
    . "Please see attached for your zipped Backup file; $backup_type \n"
    . "If this is the first backup then you should test it restores correctly to a test server. \n\n"
    . "phpMySQLAutoBackup is developed by \n\n"
    . "Have a good day now you have a backup of your MySQL db  ;-) \n\n"
    . "Please consider making a donation at: \n"
    . " \n"
    . "(any amount is gratefully received) \n";

  // Download phpMail from and upload these 3 files.
  // These 3 files are all you need to upload unless you want to use a different language file.
  // The 'require' statments below assume you create a phpmailer directory at the same level as you phpmysqlautobackup directory, e.g.

  // htdocs/phpmailer/class.phpmail.php
  // htdocs/phpmailer/class.smtp.php
  // htdocs/phpmailer/language/phpmailer.lang-en.php
  // htdocs/phpmysqlautobackup/run.php
  // htdocs/phpmysqlautobackup/etc......

  require( "../phpmailer/class.phpmailer.php" );
  require( "../phpmailer/class.smtp.php" );
  require( "../phpmailer/language/phpmailer.lang-en.php" );

   $phpmailer = new PHPMailer();

   $phpmailer -> IsSMTP();

   $phpmailer -> HostName = $phpmailer_hosthame;
   $phpmailer -> Host     = $phpmailer_host;
   $phpmailer -> Port     = $phpmailer_port;

   $phpmailer -> SMTPAuth = TRUE;
   $phpmailer -> Username = $phpmailer_username;
   $phpmailer -> Password = $phpmailer_password;

   $phpmailer -> Sender   = $phpmailer_sender;
   $phpmailer -> From     = $phpmailer_from;
   $phpmailer -> FromName = $phpmailer_fromname;

   $phpmailer -> AddAddress( $phpmailer_to, $phpmailer_toname );

   if ( !empty( $phpmailer_cc ) )
    $phpmailer -> AddCC( $phpmailer_cc, $phpmailer_ccname );

   $phpmailer -> Subject = $phpmailer_subject;
   $phpmailer -> Body    = $phpmailer_htmlbody;
   $phpmailer -> AltBody = $phpmailer_textbody;

   $attach = $phpmailer -> AddStringAttachment( $content, $file_name, $encoding = "base64", $type = "application/octet-stream" );

   $result = $phpmailer -> Send();

   if ( !$result )
      $err_msg = $phpmailer -> ErrorInfo;
      echo "ERROR: $err_msg<br />\n";

   return $result;

You also need to download phpMailer from their website ( and upload 3 files:

There are some comments in the code about where it expects to find these files, namely in a directory at the same 'level' as the phpmysqlautobackup directory. If you install phpMailer somewhere else you will need to change the code.

All the settings that phpMailer uses are in phpmysqlautobackup_extras.php and it ignores the email addresses set in run.php.

Note - although the email addresses set in run.php are not used by this hack you must still set them something (anything) as there is a check elsewhere in the code that will only send an email if they are set.

This hack could be integrated in a better way, i.e. all the settings moved into run.php and also a flag in run.php to indicate whether the existing xmail function should be used the send emails or a new phpmailer_xmail function instead. This would give users the ability to decide whether to download and install phpMailer.

I hope this is of use to someone!


Last edited by nicks on Wed Jan 23, 2008 9:15 am, edited 1 time in total.

MODS thats what I do that is! But definately NO mod music! It has to be ROCK!
Posts: 1810
Joined: Mon Oct 25, 2004 8:20 pm
Location: Huddersfield, UK

Postby davidgwalker » Wed Jan 23, 2008 8:38 am


Nice enhancement, not had time to try it yet.

If anyone else has tried this then please post your results below ;-)
I have temporarily opened this forum to public access until the spammers find it :roll:
(spammers: I will know the second your post your crap and delete it so its not worth your time...)

Thanks for your input


Return to “phpMySQLAutoBackup [forum]”

Who is online

Users browsing this forum: No registered users and 1 guest