[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-phpmailer.php (source)

   1  <?php
   2  /**
   3   * Core component classes.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Core
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Email delivery implementation using PHPMailer.
  14   *
  15   * @since 2.5.0
  16   */
  17  class BP_PHPMailer implements BP_Email_Delivery {
  18  
  19      /**
  20       * Send email(s).
  21       *
  22       * @since 2.5.0
  23       *
  24       * @param BP_Email $email Email to send.
  25       * @return bool|WP_Error Returns true if email send, else a descriptive WP_Error.
  26       */
  27  	public function bp_email( BP_Email $email ) {
  28          static $phpmailer = null;
  29  
  30          /**
  31           * Filter PHPMailer object to use.
  32           *
  33           * Specify an alternative version of PHPMailer to use instead of WordPress' default.
  34           *
  35           * @since 2.8.0
  36           *
  37           * @param null|PHPMailer $phpmailer The phpmailer class.
  38           */
  39          $phpmailer = apply_filters( 'bp_phpmailer_object', $phpmailer );
  40  
  41          if ( ! ( $phpmailer instanceof PHPMailer ) ) {
  42              if ( ! class_exists( 'PHPMailer' ) ) {
  43                  require_once ABSPATH . WPINC . '/class-phpmailer.php';
  44                  require_once ABSPATH . WPINC . '/class-smtp.php';
  45              }
  46  
  47              $phpmailer = new PHPMailer( true );
  48          }
  49  
  50  
  51          /*
  52           * Resets.
  53           */
  54          $phpmailer->MessageDate = date( 'D, j M Y H:i:s O' );
  55          $phpmailer->clearAllRecipients();
  56          $phpmailer->clearAttachments();
  57          $phpmailer->clearCustomHeaders();
  58          $phpmailer->clearReplyTos();
  59          $phpmailer->Sender = '';
  60  
  61  
  62          /*
  63           * Set up.
  64           */
  65  
  66          $phpmailer->IsMail();
  67          $phpmailer->CharSet = bp_get_option( 'blog_charset' );
  68  
  69  
  70          /*
  71           * Content.
  72           */
  73  
  74          $phpmailer->Subject = $email->get_subject( 'replace-tokens' );
  75          $content_plaintext  = PHPMailer::normalizeBreaks( $email->get_content_plaintext( 'replace-tokens' ) );
  76  
  77          if ( $email->get( 'content_type' ) === 'html' ) {
  78              $phpmailer->msgHTML( $email->get_template( 'add-content' ) );
  79              $phpmailer->AltBody = $content_plaintext;
  80  
  81          } else {
  82              $phpmailer->IsHTML( false );
  83              $phpmailer->Body = $content_plaintext;
  84          }
  85  
  86          $recipient = $email->get_from();
  87          try {
  88              $phpmailer->SetFrom( $recipient->get_address(), $recipient->get_name(), false );
  89          } catch ( phpmailerException $e ) {
  90          }
  91  
  92          $recipient = $email->get_reply_to();
  93          try {
  94              $phpmailer->addReplyTo( $recipient->get_address(), $recipient->get_name() );
  95          } catch ( phpmailerException $e ) {
  96          }
  97  
  98          $recipients = $email->get_to();
  99          foreach ( $recipients as $recipient ) {
 100              try {
 101                  $phpmailer->AddAddress( $recipient->get_address(), $recipient->get_name() );
 102              } catch ( phpmailerException $e ) {
 103              }
 104          }
 105  
 106          $recipients = $email->get_cc();
 107          foreach ( $recipients as $recipient ) {
 108              try {
 109                  $phpmailer->AddCc( $recipient->get_address(), $recipient->get_name() );
 110              } catch ( phpmailerException $e ) {
 111              }
 112          }
 113  
 114          $recipients = $email->get_bcc();
 115          foreach ( $recipients as $recipient ) {
 116              try {
 117                  $phpmailer->AddBcc( $recipient->get_address(), $recipient->get_name() );
 118              } catch ( phpmailerException $e ) {
 119              }
 120          }
 121  
 122          $headers = $email->get_headers();
 123          foreach ( $headers as $name => $content ) {
 124              $phpmailer->AddCustomHeader( $name, $content );
 125          }
 126  
 127  
 128          /**
 129           * Fires after PHPMailer is initialised.
 130           *
 131           * @since 2.5.0
 132           *
 133           * @param PHPMailer $phpmailer The PHPMailer instance.
 134           */
 135          do_action( 'bp_phpmailer_init', $phpmailer );
 136  
 137          /** This filter is documented in wp-includes/pluggable.php */
 138          do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
 139  
 140          try {
 141              return $phpmailer->Send();
 142          } catch ( phpmailerException $e ) {
 143              return new WP_Error( $e->getCode(), $e->getMessage(), $email );
 144          }
 145      }
 146  
 147  
 148      /*
 149       * Utility/helper functions.
 150       */
 151  
 152      /**
 153       * Get an appropriate hostname for the email. Varies depending on site configuration.
 154       *
 155       * @since 2.5.0
 156       * @deprecated 2.5.3 No longer used.
 157       *
 158       * @return string
 159       */
 160  	public static function get_hostname() {
 161          return '';
 162      }
 163  }


Generated: Sun Jul 12 01:01:53 2020 Cross-referenced by PHPXref 0.7.1