public/wordpress/wp-content/plugins/backupbuddy/classes/core.php
/*	mail_error()
	 *	
	 *	Sends an error email to the defined email address(es) on settings page.
	 *	
	 *	@param		string			$message	Message to be included in the body of the email.
	 *	@param		string			$override_recipient	Email address(es) to send to instead of the normal recipient.
	 *	@param		string|array 	String or array of filename(s) to send as email attachments.
	 *	@return		null
	 */


Sends an error email to the defined email address(es) on settings page.

@param          string                  $message        Message to be included in the body of the email.
@param          string                  $override_recipient     Email address(es) to send to instead of the normal recipient.
@param          string|array    String or array of filename(s) to send as email attachments.
@return         null
Sends an error email to the defined email address ( es ) on settings page . @param string $message Message to be included in the body of the email . @param string $override_recipient Email address ( es ) to send to instead of the normal recipient . @param string|array String or array of filename ( s ) to send as email attachments . @return null
public static function mail_error( $message, $override_recipient = '', $attachments = array() ) {
		require_once( pb_backupbuddy::plugin_path() . '/classes/constants.php' );
		if ( !isset( pb_backupbuddy::$options ) ) {
			pb_backupbuddy::load();
		}
		if ( ( ! is_array( pb_backupbuddy::$options ) ) || ( ! isset( pb_backupbuddy::$options['data_version'] ) ) ) {
			$settings_copy = pb_backupbuddy::settings( 'default_options' );
		} else {
			$settings_copy = pb_backupbuddy::$options;
		}
		if ( ( time() - $settings_copy['last_error_email_time'] ) < backupbuddy_constants::MIMIMUM_TIME_BETWEEN_ERROR_EMAILS ) {
			pb_backupbuddy::status( 'warning', 'Warning #4389484: Tried to send error email too fast. Skipping send. Message: `' . $message . '`.' );
			return true;
		}
		$settings_copy['last_error_email_time'] = time();
		pb_backupbuddy::save();
		$subject = $settings_copy['email_notify_error_subject'];
		$body = $settings_copy['email_notify_error_body'];
		$replacements = array(
			'{site_url}' => site_url(),
			'{home_url}' => home_url(),
			'{backupbuddy_version}' => pb_backupbuddy::settings( 'version' ),
			'{current_datetime}' => date(DATE_RFC822),
			'{heading}' => 'BackupBuddy Error',
			'{support_display}' => 'table',
			'{message}' => $message
		);
		foreach( $replacements as $replace_key => $replacement ) {
			$subject = str_replace( $replace_key, $replacement, $subject );
			$body = str_replace( $replace_key, $replacement, $body );
		}
		$replacements['{body}'] = $body;
		if ( @file_exists( get_theme_root() . '/backupbuddy-email-template.php' ) ) {
			$body = file_get_contents( get_theme_root() . '/backupbuddy-email-template.php' );
		} else {
			$body = file_get_contents( dirname( dirname( __FILE__ ) ) . '/views/backupbuddy-email-template.php' );
		}
		foreach( $replacements as $replace_key => $replacement ) {
			$body = str_replace( $replace_key,$replacement, $body );
		}
		$email = $settings_copy['email_notify_error'];
		if ( $override_recipient != '' ) {
			$email = $override_recipient;
			pb_backupbuddy::status( 'details', 'Overriding email recipient to: `' . $override_recipient . '`.' );
		}
		if ( '' == $email ) {
			$email = get_option('admin_email');
		}
		if ( ! empty( $email ) ) {
			pb_backupbuddy::status( 'details', 'Sending email error notification with subject `' . $subject . '` to recipient(s): `' . $email . '`.' );
			if ( $settings_copy['email_return'] != '' ) {
				$email_return = $settings_copy['email_return'];
			} else {
				$email_return = get_option('admin_email');
			}
			if ( function_exists( 'wp_mail' ) ) {
				$result = wp_mail( $email, $subject, $body, 'From: BackupBuddy <' . $email_return . ">\r\n" . 'Content-Type: text/html;' . "\r\n".'Reply-To: '.get_option('admin_email')."\r\n", $attachments );
				if ( false === $result ) {
					pb_backupbuddy::status( 'error', 'Error #45443554: Unable to send error email with WordPress wp_mail(). Verify WordPress & Server settings.' );
				}
			} else {
				pb_backupbuddy::status( 'error', 'Warning #3289239: wp_mail() unavailable. Inside WordPress?' );
			}
		} else {
			pb_backupbuddy::status( 'warning', 'No email addresses are set to receive error notifications on the Settings page AND get_option("admin_email") not set. Setting a notification email is suggested.' );
		}
	}
public static function mail_error ( $ message , $ override_recipient = '' , $ attachments = array ( ) ) { require_once ( pb_backupbuddy :: plugin_path ( ) . '/classes/constants.php' ) ; if ( ! isset ( pb_backupbuddy :: $ options ) ) { pb_backupbuddy :: load ( ) ; } if ( ( ! is_array ( pb_backupbuddy :: $ options ) ) || ( ! isset ( pb_backupbuddy :: $ options [ 'data_version' ] ) ) ) { $ settings_copy = pb_backupbuddy :: settings ( 'default_options' ) ; } else { $ settings_copy = pb_backupbuddy :: $ options ; } if ( ( time ( ) - $ settings_copy [ 'last_error_email_time' ] ) < backupbuddy_constants :: MIMIMUM_TIME_BETWEEN_ERROR_EMAILS ) { pb_backupbuddy :: status ( 'warning' , 'Warning #4389484: Tried to send error email too fast. Skipping send. Message: `' . $ message . '`.' ) ; return true ; } $ settings_copy [ 'last_error_email_time' ] = time ( ) ; pb_backupbuddy :: save ( ) ; $ subject = $ settings_copy [ 'email_notify_error_subject' ] ; $ body = $ settings_copy [ 'email_notify_error_body' ] ; $ replacements = array ( '{site_url}' => site_url ( ) , '{home_url}' => home_url ( ) , '{backupbuddy_version}' => pb_backupbuddy :: settings ( 'version' ) , '{current_datetime}' => date ( DATE_RFC822 ) , '{heading}' => 'BackupBuddy Error' , '{support_display}' => 'table' , '{message}' => $ message ) ; foreach ( $ replacements as $ replace_key => $ replacement ) { $ subject = str_replace ( $ replace_key , $ replacement , $ subject ) ; $ body = str_replace ( $ replace_key , $ replacement , $ body ) ; } $ replacements [ '{body}' ] = $ body ; if ( @ file_exists ( get_theme_root ( ) . '/backupbuddy-email-template.php' ) ) { $ body = file_get_contents ( get_theme_root ( ) . '/backupbuddy-email-template.php' ) ; } else { $ body = file_get_contents ( dirname ( dirname ( __FILE__ ) ) . '/views/backupbuddy-email-template.php' ) ; } foreach ( $ replacements as $ replace_key => $ replacement ) { $ body = str_replace ( $ replace_key , $ replacement , $ body ) ; } $ email = $ settings_copy [ 'email_notify_error' ] ; if ( $ override_recipient != '' ) { $ email = $ override_recipient ; pb_backupbuddy :: status ( 'details' , 'Overriding email recipient to: `' . $ override_recipient . '`.' ) ; } if ( '' == $ email ) { $ email = get_option ( 'admin_email' ) ; } if ( ! empty ( $ email ) ) { pb_backupbuddy :: status ( 'details' , 'Sending email error notification with subject `' . $ subject . '` to recipient(s): `' . $ email . '`.' ) ; if ( $ settings_copy [ 'email_return' ] != '' ) { $ email_return = $ settings_copy [ 'email_return' ] ; } else { $ email_return = get_option ( 'admin_email' ) ; } if ( function_exists ( 'wp_mail' ) ) { $ result = wp_mail ( $ email , $ subject , $ body , 'From: BackupBuddy <' . $ email_return . " > \r \n " . 'Content-Type: text/html;' . " \r \n " . 'Reply-To: ' . get_option ( 'admin_email' ) . " \r \n " , $ attachments ) ; if ( false === $ result ) { pb_backupbuddy :: status ( 'error' , 'Error #45443554: Unable to send error email with WordPress wp_mail(). Verify WordPress & Server settings.' ) ; } } else { pb_backupbuddy :: status ( 'error' , 'Warning #3289239: wp_mail() unavailable. Inside WordPress?' ) ; } } else { pb_backupbuddy :: status ( 'warning' , 'No email addresses are set to receive error notifications on the Settings page AND get_option("admin_email") not set. Setting a notification email is suggested.' ) ; } }
mail_error()
mail_error ()
// If there is an error due to a problem with the plugin settings then load defaults temporarily. // Track last sent time to prevent flood. // Customize Subject and user customizable message // Customize the final body based on our HTML template // Default to admin_email if not configured anywhere else.