> > > > >

 
get_email_array( $_POST['emailaddress'] ) ) : '' ); BackWPup_Option::update( $jobid, 'emailefilesize', ! empty( $_POST['emailefilesize'] ) ? absint( $_POST['emailefilesize'] ) : 0 ); BackWPup_Option::update( $jobid, 'emailsndemail', sanitize_email( $_POST['emailsndemail'] ) ); BackWPup_Option::update( $jobid, 'emailmethod', ( $_POST['emailmethod'] === '' || $_POST['emailmethod'] === 'mail' || $_POST['emailmethod'] === 'sendmail' || $_POST['emailmethod'] === 'smtp' ) ? $_POST['emailmethod'] : '' ); BackWPup_Option::update( $jobid, 'emailsendmail', sanitize_text_field( $_POST['emailsendmail'] ) ); BackWPup_Option::update( $jobid, 'emailsndemailname', sanitize_text_field( $_POST['emailsndemailname'] ) ); BackWPup_Option::update( $jobid, 'emailhost', sanitize_text_field( $_POST['emailhost'] ) ); BackWPup_Option::update( $jobid, 'emailhostport', absint( $_POST['emailhostport'] ) ); BackWPup_Option::update( $jobid, 'emailsecure', ( $_POST['emailsecure'] === 'ssl' || $_POST['emailsecure'] === 'tls' ) ? $_POST['emailsecure'] : '' ); BackWPup_Option::update( $jobid, 'emailuser', sanitize_text_field( $_POST['emailuser'] ) ); BackWPup_Option::update( $jobid, 'emailpass', BackWPup_Encryption::encrypt( $_POST['emailpass'] ) ); } /** * @param $job_object * * @return bool */ public function job_run_archive( BackWPup_Job $job_object ) { $job_object->substeps_todo = 1; $job_object->log( sprintf( __( '%d. Try to send backup with email …', 'backwpup' ), $job_object->steps_data[ $job_object->step_working ]['STEP_TRY'] ), E_USER_NOTICE ); //check file Size if ( ! empty( $job_object->job['emailefilesize'] ) ) { if ( $job_object->backup_filesize > $job_object->job['emailefilesize'] * 1024 * 1024 ) { $job_object->log( __( 'Backup archive too big to be sent by email!', 'backwpup' ), E_USER_ERROR ); $job_object->substeps_done = 1; return true; } } $job_object->log( sprintf( __( 'Sending email to %s…', 'backwpup' ), $job_object->job['emailaddress'] ), E_USER_NOTICE ); //get mail settings $emailmethod = 'mail'; $emailsendmail = ''; $emailhost = ''; $emailhostport = ''; $emailsecure = ''; $emailuser = ''; $emailpass = ''; if ( empty( $job_object->job['emailmethod'] ) ) { //do so if i'm the wp_mail to get the settings global $phpmailer; // (Re)create it, if it's gone missing if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer( true ); } //only if PHPMailer really used if ( is_object( $phpmailer ) ) { do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); //get settings from PHPMailer $emailmethod = $phpmailer->Mailer; $emailsendmail = $phpmailer->Sendmail; $emailhost = $phpmailer->Host; $emailhostport = $phpmailer->Port; $emailsecure = $phpmailer->SMTPSecure; $emailuser = $phpmailer->Username; $emailpass = $phpmailer->Password; } } else { $emailmethod = $job_object->job['emailmethod']; $emailsendmail = $job_object->job['emailsendmail']; $emailhost = $job_object->job['emailhost']; $emailhostport = $job_object->job['emailhostport']; $emailsecure = $job_object->job['emailsecure']; $emailuser = $job_object->job['emailuser']; $emailpass = BackWPup_Encryption::decrypt( $job_object->job['emailpass'] ); } //Generate mail with Swift Mailer if ( ! class_exists( 'Swift', false ) ) { require BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php'; } if ( function_exists( 'mb_internal_encoding' ) && ( (int) ini_get( 'mbstring.func_overload' ) ) & 2 ) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding( 'ASCII' ); } try { //Set Temp dir for mailing Swift_Preferences::getInstance()->setTempDir( untrailingslashit( BackWPup::get_plugin_data( 'TEMP' ) ) )->setCacheType( 'disk' ); // Create the Transport if ( $emailmethod == 'smtp' ) { $transport = Swift_SmtpTransport::newInstance( $emailhost, $emailhostport ); if ( $emailuser ) { $transport->setUsername( $emailuser ); $transport->setPassword( $emailpass ); } if ( $emailsecure == 'ssl' ) { $transport->setEncryption( 'ssl' ); } if ( $emailsecure == 'tls' ) { $transport->setEncryption( 'tls' ); } } elseif ( $emailmethod == 'sendmail' ) { $transport = Swift_SendmailTransport::newInstance( $emailsendmail ); } else { $job_object->need_free_memory( $job_object->backup_filesize * 8 ); $transport = Swift_MailTransport::newInstance(); } // Create the Mailer using your created Transport $emailer = Swift_Mailer::newInstance( $transport ); // Create a message $message = Swift_Message::newInstance( sprintf( __( 'BackWPup archive from %1$s: %2$s', 'backwpup' ), date_i18n( 'd-M-Y H:i', $job_object->start_time, true ), esc_attr( $job_object->job['name'] ) ) ); $message->setFrom( array( $job_object->job['emailsndemail'] => $job_object->job['emailsndemailname'] ) ); $message->setTo( $this->get_email_array( $job_object->job['emailaddress'] ) ); $message->setBody( sprintf( __( 'Backup archive: %s', 'backwpup' ), $job_object->backup_file ), 'text/plain', strtolower( get_bloginfo( 'charset' ) ) ); $message->attach( Swift_Attachment::fromPath( $job_object->backup_folder . $job_object->backup_file, MimeTypeExtractor::fromFilePath( $job_object->backup_folder . $job_object->backup_file ) ) ); // Send the message $result = $emailer->send( $message ); } catch ( Exception $e ) { $job_object->log( 'Swift Mailer: ' . $e->getMessage(), E_USER_ERROR ); } if ( isset( $mbEncoding ) ) { mb_internal_encoding( $mbEncoding ); } if ( ! isset( $result ) || ! $result ) { $job_object->log( __( 'Error while sending email!', 'backwpup' ), E_USER_ERROR ); return false; } else { $job_object->substeps_done = 1; $job_object->log( __( 'Email sent.', 'backwpup' ), E_USER_NOTICE ); return true; } } /** * @param $job_settings * * @return bool */ public function can_run( array $job_settings ) { if ( empty( $job_settings['emailaddress'] ) ) { return false; } if ( $job_settings['backuptype'] != 'archive' ) { return false; } return true; } /** * sends test mail */ public function edit_ajax() { check_ajax_referer( 'backwpup_ajax_nonce' ); //get mail settings $emailmethod = 'mail'; $emailsendmail = ''; $emailhost = ''; $emailhostport = ''; $emailsecure = ''; $emailuser = ''; $emailpass = ''; if ( empty( $_POST['emailmethod'] ) ) { //do so if i'm the wp_mail to get the settings global $phpmailer; // (Re)create it, if it's gone missing if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; $phpmailer = new PHPMailer( true ); } //only if PHPMailer really used if ( is_object( $phpmailer ) ) { do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); //get settings from PHPMailer $emailmethod = $phpmailer->Mailer; $emailsendmail = $phpmailer->Sendmail; $emailhost = $phpmailer->Host; $emailhostport = $phpmailer->Port; $emailsecure = $phpmailer->SMTPSecure; $emailuser = $phpmailer->Username; $emailpass = $phpmailer->Password; } } else { $emailmethod = sanitize_text_field( $_POST['emailmethod'] ); $emailsendmail = sanitize_email( $_POST['emailsendmail'] ); $emailhost = sanitize_text_field( $_POST['emailhost'] ); $emailhostport = absint( $_POST['emailhostport'] ); $emailsecure = sanitize_text_field( $_POST['emailsecure'] ); $emailuser = sanitize_text_field( $_POST['emailuser'] ); $emailpass = BackWPup_Encryption::decrypt( $_POST['emailpass'] ); } //Generate mail with Swift Mailer if ( ! class_exists( 'Swift', false ) ) { require BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php'; } if ( function_exists( 'mb_internal_encoding' ) && ( (int) ini_get( 'mbstring.func_overload' ) ) & 2 ) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding( 'ASCII' ); } try { // Create the Transport if ( $emailmethod == 'smtp' ) { $transport = Swift_SmtpTransport::newInstance( $emailhost, $emailhostport ); if ( $emailuser ) { $transport->setUsername( $emailuser ); $transport->setPassword( $emailpass ); } if ( $emailsecure == 'ssl' ) { $transport->setEncryption( 'ssl' ); } if ( $emailsecure == 'tls' ) { $transport->setEncryption( 'tls' ); } } elseif ( $emailmethod == 'sendmail' ) { $transport = Swift_SendmailTransport::newInstance( $emailsendmail ); } else { $transport = Swift_MailTransport::newInstance(); } // Create the Mailer using your created Transport $emailer = Swift_Mailer::newInstance( $transport ); // Create a message $message = Swift_Message::newInstance( __( 'BackWPup archive sending TEST Message', 'backwpup' ) ); $message->setFrom( array( $_POST['emailsndemail'] => sanitize_email( $_POST['emailsndemailname'] ) ) ); $message->setTo( $this->get_email_array( $_POST['emailaddress'] ) ); $message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'backwpup' ) ); // Send the message $result = $emailer->send( $message ); } catch ( Exception $e ) { echo 'Swift Mailer: ' . $e->getMessage() . ''; } if ( isset( $mbEncoding ) ) { mb_internal_encoding( $mbEncoding ); } if ( ! isset( $result ) || ! $result ) { echo '' . esc_html__( 'Error while sending email!', 'backwpup' ) . ''; } else { echo '' . esc_html__( 'Email sent.', 'backwpup' ) . ''; } die(); } /** * Get an array of emails from comma-separated string. * * @param string $emailString * * @return array */ private function get_email_array( $emailString ) { $emails = explode( ',', sanitize_text_field( $emailString ) ); foreach ( $emails as $key => $email ) { $emails[ $key ] = sanitize_email( trim( $email ) ); if ( ! is_email( $emails[ $key ] ) ) { unset( $emails[ $key ] ); } } return $emails; } }