clearCustomHeaders() 공개 메소드

Clear all custom headers.
public clearCustomHeaders ( ) : void
리턴 void
예제 #1
5
 /**
  * Inner mailer initialization from set variables
  *
  * @return void
  */
 protected function initMailFromSet()
 {
     $this->mail->setLanguage($this->get('langLocale'), $this->get('langPath'));
     $this->mail->CharSet = $this->get('charset');
     $this->mail->From = $this->get('from');
     $this->mail->FromName = $this->get('fromName') ?: $this->get('from');
     $this->mail->Sender = $this->get('from');
     $this->mail->clearAllRecipients();
     $this->mail->clearAttachments();
     $this->mail->clearCustomHeaders();
     $emails = explode(static::MAIL_SEPARATOR, $this->get('to'));
     foreach ($emails as $email) {
         $this->mail->addAddress($email);
     }
     $this->mail->Subject = $this->get('subject');
     $this->mail->AltBody = $this->createAltBody($this->get('body'));
     $this->mail->Body = $this->get('body');
     // add custom headers
     foreach ($this->get('customHeaders') as $header) {
         $this->mail->addCustomHeader($header);
     }
     if (is_array($this->get('images'))) {
         foreach ($this->get('images') as $image) {
             // Append to $attachment array
             $this->mail->addEmbeddedImage($image['path'], $image['name'] . '@mail.lc', $image['name'], 'base64', $image['mime']);
         }
     }
 }
예제 #2
1
 /**
  * Miscellaneous calls to improve test coverage and some small tests.
  */
 public function testMiscellaneous()
 {
     $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
     $this->Mail->addCustomHeader('SomeHeader: Some Value');
     $this->Mail->clearCustomHeaders();
     $this->Mail->clearAttachments();
     $this->Mail->isHTML(false);
     $this->Mail->isSMTP();
     $this->Mail->isMail();
     $this->Mail->isSendmail();
     $this->Mail->isQmail();
     $this->Mail->setLanguage('fr');
     $this->Mail->Sender = '';
     $this->Mail->createHeader();
     $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
     $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
     //Test pathinfo
     $a = '/mnt/files/飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], '/mnt/files', 'UNIX dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'UNIX basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'UNIX extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'UNIX filename not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, PATHINFO_DIRNAME), '/mnt/files', 'Dirname path element not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, 'filename'), '飛兒樂 團光茫', 'Filename path element not matched');
     $a = 'c:\\mnt\\files\\飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], 'c:\\mnt\\files', 'Windows dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'Windows basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'Windows extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'Windows filename not matched');
 }
예제 #3
1
 /**
  * Tests the Custom header getter
  */
 public function testCustomHeaderGetter()
 {
     $this->Mail->addCustomHeader('foo', 'bar');
     $this->assertEquals([['foo', 'bar']], $this->Mail->getCustomHeaders());
     $this->Mail->addCustomHeader('foo', 'baz');
     $this->assertEquals([['foo', 'bar'], ['foo', 'baz']], $this->Mail->getCustomHeaders());
     $this->Mail->clearCustomHeaders();
     $this->assertEmpty($this->Mail->getCustomHeaders());
     $this->Mail->addCustomHeader('yux');
     $this->assertEquals([['yux']], $this->Mail->getCustomHeaders());
     $this->Mail->addCustomHeader('Content-Type: application/json');
     $this->assertEquals([['yux'], ['Content-Type', ' application/json']], $this->Mail->getCustomHeaders());
 }
 /**
  * Send email(s).
  *
  * @since 2.5.0
  *
  * @param BP_Email $email Email to send.
  * @return bool|WP_Error Returns true if email send, else a descriptive WP_Error.
  */
 public function bp_email(BP_Email $email)
 {
     static $phpmailer = null;
     if ($phpmailer === null) {
         if (!class_exists('PHPMailer')) {
             require_once ABSPATH . WPINC . '/class-phpmailer.php';
             require_once ABSPATH . WPINC . '/class-smtp.php';
         }
         $phpmailer = new PHPMailer(true);
     }
     /*
      * Resets.
      */
     $phpmailer->clearAllRecipients();
     $phpmailer->clearAttachments();
     $phpmailer->clearCustomHeaders();
     $phpmailer->clearReplyTos();
     $phpmailer->Sender = '';
     /*
      * Set up.
      */
     $phpmailer->IsMail();
     $phpmailer->CharSet = bp_get_option('blog_charset');
     $phpmailer->Hostname = self::get_hostname();
     /*
      * Content.
      */
     $phpmailer->Subject = $email->get_subject('replace-tokens');
     $content_plaintext = PHPMailer::normalizeBreaks($email->get_content_plaintext('replace-tokens'));
     if ($email->get('content_type') === 'html') {
         $phpmailer->msgHTML($email->get_template('add-content'), '', 'wp_strip_all_tags');
         $phpmailer->AltBody = $content_plaintext;
     } else {
         $phpmailer->IsHTML(false);
         $phpmailer->Body = $content_plaintext;
     }
     $recipient = $email->get_from();
     try {
         $phpmailer->SetFrom($recipient->get_address(), $recipient->get_name(), false);
     } catch (phpmailerException $e) {
     }
     $recipient = $email->get_reply_to();
     try {
         $phpmailer->addReplyTo($recipient->get_address(), $recipient->get_name());
     } catch (phpmailerException $e) {
     }
     $recipients = $email->get_to();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddAddress($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $recipients = $email->get_cc();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddCc($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $recipients = $email->get_bcc();
     foreach ($recipients as $recipient) {
         try {
             $phpmailer->AddBcc($recipient->get_address(), $recipient->get_name());
         } catch (phpmailerException $e) {
         }
     }
     $headers = $email->get_headers();
     foreach ($headers as $name => $content) {
         $phpmailer->AddCustomHeader($name, $content);
     }
     /**
      * Fires after PHPMailer is initialised.
      *
      * @since 2.5.0
      *
      * @param PHPMailer $phpmailer The PHPMailer instance.
      */
     do_action('bp_phpmailer_init', $phpmailer);
     /** This filter is documented in wp-includes/pluggable.php */
     do_action_ref_array('phpmailer_init', array(&$phpmailer));
     try {
         return $phpmailer->Send();
     } catch (phpmailerException $e) {
         return new WP_Error($e->getCode(), $e->getMessage(), $email);
     }
 }
예제 #5
0
 $mail->SetFrom($this->sub_from_mail, $name = $this->sub_from_title);
 $mail->AddReplyTo($this->sub_reply_mail, $this->sub_from_title);
 if ($this->sub_mail_attach != '') {
     $attData = curl_get_result($this->sub_mail_attach);
     if ($attData === false) {
         # File Error
     } else {
         $mail->AddStringAttachment($attData, basename($this->sub_mail_attach), $encoding = 'base64', $type = 'application/octet-stream');
     }
 }
 # ** Receivers
 foreach ($this->sub_mail_receiver as $key => $value) {
     # *************************************************************************
     /* Clear Mails */
     $mail->clearAddresses();
     $mail->clearCustomHeaders();
     $mail->clearAllRecipients();
     $mail->AddAddress($key, $value['name']);
     $mail->addCustomHeader("X-Lethe-Receiver: " . $key);
     $mail->addCustomHeader("X-Lethe-ID: " . $this->sub_mail_id);
     $mail->addCustomHeader("X-Mailer: Lethe Newsletter v" . LETHE_VERSION . ' http://www.newslether.com/');
     $mail->addCustomHeader("X-Mailer: Powered by Artlantis Design Studio http://www.artlantis.net/");
     $mail->Subject = $value['subject'];
     $mail->AltBody = $value['altbody'];
     $mail->MsgHTML($value['body']);
     /* Send Error */
     if (!$mail->Send()) {
         $this->sendingErrors = $mail->ErrorInfo;
         $this->sendPos = false;
     } else {
         /* Sent Done */
예제 #6
-4
 /**
  * Send a prepared and rendered email locally.
  *
  * @param array $email
  * @return bool
  */
 protected function send_prepared(array $email)
 {
     if (!is_email($email['to_address'])) {
         Prompt_Logging::add_error(Prompt_Enum_Error_Codes::OUTBOUND, __('Attempted to send to an invalid email address.', 'Postmatic'), compact('email'));
         return false;
     }
     $this->local_mailer->clearAllRecipients();
     $this->local_mailer->clearCustomHeaders();
     $this->local_mailer->clearReplyTos();
     $this->local_mailer->From = $email['from_address'];
     $this->local_mailer->FromName = $email['from_name'];
     $this->local_mailer->addAddress($email['to_address'], $email['to_name']);
     if (!empty($email['reply_address'])) {
         $this->local_mailer->addReplyTo($email['reply_address'], $email['reply_name']);
     }
     $unsubscribe_types = array(Prompt_Enum_Message_Types::COMMENT, Prompt_Enum_Message_Types::POST);
     if (!empty($email['reply_address']) and in_array($email['message_type'], $unsubscribe_types)) {
         $this->local_mailer->addCustomHeader('List-Unsubscribe', '<mailto:' . $email['reply_address'] . '?body=unsubscribe>');
     }
     $this->local_mailer->Subject = $email['subject'];
     $this->local_mailer->Body = $email['html_content'];
     $this->local_mailer->AltBody = $email['text_content'];
     $this->local_mailer->ContentType = Prompt_Enum_Content_Types::HTML;
     $this->local_mailer->isMail();
     $this->local_mailer->CharSet = 'UTF-8';
     try {
         $this->local_mailer->send();
     } catch (phpmailerException $e) {
         Prompt_Logging::add_error('prompt_wp_mail', __('Failed sending an email locally. Did you know Postmatic can deliver email for you?', 'Prompt_Core'), array('email' => $email, 'error_info' => $this->local_mailer->ErrorInfo));
         return false;
     }
     return true;
 }