<?php
/*
 * Retry wrapper for mail() + Logging
 *
 * Paul Gregg <pgregg@pgregg.com>
 * 4th May 2003
 * Copyright 2003, Paul Gregg
 *
 * Open Source Code:   If you use this code on your site for public
 * access (i.e. on the Internet) then you must attribute the author and
 * source web site: http://www.pgregg.com/projects/php/code/maillog.phps
 *
 */

    
Function MailLog($to$subject$message$additional_headers=''$additional_parameters='') {
        if (
$GLOBALS['ISDEV']) // let me see errors
          
$suc mail($to$subject$message$additional_headers$additional_parameters);
        else
          
$suc = @mail($to$subject$message$additional_headers$additional_parameters);
        
$log = ($suc 'Success ' 'Failed  ') . ": Sending mail to $to ($subject)";
        
ErrorLog($log);
        if (!
$suc) { // lets try again
          
$retrys 3;
          while(!
$suc && $retrys 0) {
              
$retrys--;
                
sleep(2);
                
$suc = @mail($to$subject$message$additional_headers$additional_parameters);
                
$log = ($suc 'RETRY Success ' 'RETRY Failed  ') . ": Sending mail to $to ($subject)";
                
ErrorLog($log);
          }
        }
        if (!
$sucErrorLog("FAILED  : Giving up on mail to $to ($subject)");
        return 
$suc;
    }

    Function 
ErrorLog($message) {
        
$timest Date('d/m/Y H:i:s'time());
        
$crlf '/[' chr(10) . chr(13) . ']/';
        
$message preg_replace($crlf''$message);
        
$log_msg $timest ' ' $message "\r\n";
        
error_log($log_msg,
            
3'C:/TEMP/OSS_ErrorLog.txt');
    }
?>