clearReplyTos() public method

Clear all ReplyTo recipients.
public clearReplyTos ( ) : void
return void
Esempio n. 1
16
 /**
  * Tests removal of duplicate recipients and reply-tos.
  */
 public function testDuplicateIDNRemoved()
 {
     if (!$this->Mail->idnSupported()) {
         $this->markTestSkipped('intl and/or mbstring extensions are not available');
     }
     $this->Mail->clearAllRecipients();
     $this->Mail->clearReplyTos();
     $this->Mail->CharSet = 'utf-8';
     $this->assertTrue($this->Mail->addAddress('test@françois.ch'));
     $this->assertFalse($this->Mail->addAddress('test@françois.ch'));
     $this->assertTrue($this->Mail->addAddress('test@FRANÇOIS.CH'));
     $this->assertFalse($this->Mail->addAddress('test@FRANÇOIS.CH'));
     $this->assertTrue($this->Mail->addAddress('*****@*****.**'));
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'));
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'));
     $this->assertTrue($this->Mail->addReplyTo('test+replyto@françois.ch'));
     $this->assertFalse($this->Mail->addReplyTo('test+replyto@françois.ch'));
     $this->assertTrue($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH'));
     $this->assertFalse($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH'));
     $this->assertTrue($this->Mail->addReplyTo('*****@*****.**'));
     $this->assertFalse($this->Mail->addReplyTo('*****@*****.**'));
     $this->assertFalse($this->Mail->addReplyTo('*****@*****.**'));
     $this->buildBody();
     $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
     // There should be only one "To" address and one "Reply-To" address.
     $this->assertEquals(1, count($this->Mail->getToAddresses()), 'Bad count of "to" recipients');
     $this->assertEquals(1, count($this->Mail->getReplyToAddresses()), 'Bad count of "reply-to" addresses');
 }
Esempio n. 2
0
File: Mail.php Progetto: yupe/yupe
 /**
  * Функция отправки сообщения:
  *
  * @param string $from - адрес отправителя
  * @param string|array $to - адрес(-а) получателя
  * @param string $theme - тема письма
  * @param string $body - тело письма
  * @param bool $isText - является ли тело письма текстом
  * @param array $replyTo добавляет заголовок Reply-To, формат [email => имя]
  *
  * @return bool отправилось ли письмо
  **/
 public function send($from, $to, $theme, $body, $isText = false, $replyTo = [])
 {
     $this->_mailer->clearAllRecipients();
     $this->setFrom($from);
     if (is_array($to)) {
         foreach ($to as $email) {
             $this->addAddress($email);
         }
     } else {
         $this->addAddress($to);
     }
     $this->setSubject($theme);
     if ($isText) {
         $this->_mailer->Body = $body;
         $this->_mailer->isHTML(false);
     } else {
         $this->_mailer->msgHTML($body, \Yii::app()->basePath);
     }
     if (!empty($replyTo)) {
         $this->_mailer->clearReplyTos();
         foreach ($replyTo as $email => $name) {
             $this->_mailer->addReplyTo($email, $name);
         }
     }
     try {
         return $this->_mailer->send();
     } catch (\Exception $e) {
         \Yii::log($e->__toString(), \CLogger::LEVEL_ERROR, 'mail');
         return false;
     }
 }
Esempio n. 3
0
 /**
  * Test addressing.
  */
 public function testAddressing()
 {
     $this->assertFalse($this->Mail->addAddress(''), 'Empty address accepted');
     $this->assertFalse($this->Mail->addAddress('', 'Nobody'), 'Empty address with name accepted');
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'), 'Invalid address accepted');
     $this->assertTrue($this->Mail->addAddress('*****@*****.**'), 'Addressing failed');
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'), 'Duplicate addressing failed');
     $this->assertTrue($this->Mail->addCC('*****@*****.**'), 'CC addressing failed');
     $this->assertFalse($this->Mail->addCC('*****@*****.**'), 'CC duplicate addressing failed');
     $this->assertFalse($this->Mail->addCC('*****@*****.**'), 'CC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->addBCC('*****@*****.**'), 'BCC addressing failed');
     $this->assertFalse($this->Mail->addBCC('*****@*****.**'), 'BCC duplicate addressing failed');
     $this->assertFalse($this->Mail->addBCC('*****@*****.**'), 'BCC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->addReplyTo('*****@*****.**'), 'Replyto Addressing failed');
     $this->assertFalse($this->Mail->addReplyTo('*****@*****.**'), 'Invalid Replyto address accepted');
     $this->assertTrue($this->Mail->setFrom('*****@*****.**', 'some name'), 'setFrom failed');
     $this->assertFalse($this->Mail->setFrom('a@example.com.', 'some name'), 'setFrom accepted invalid address');
     $this->Mail->Sender = '';
     $this->Mail->setFrom('*****@*****.**', 'some name', true);
     $this->assertEquals($this->Mail->Sender, '*****@*****.**', 'setFrom failed to set sender');
     $this->Mail->Sender = '';
     $this->Mail->setFrom('*****@*****.**', 'some name', false);
     $this->assertEquals($this->Mail->Sender, '', 'setFrom should not have set sender');
     $this->Mail->clearCCs();
     $this->Mail->clearBCCs();
     $this->Mail->clearReplyTos();
 }
Esempio n. 4
0
 /**
  * Clears all recipients assigned in the ReplyTo array.  Returns void.
  *
  * @return null
  */
 public function clearReplyTos()
 {
     $this->_aReplies = array();
     parent::clearReplyTos();
 }
 /**
  * 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);
     }
 }
Esempio n. 6
0
 /**
  * Remetente
  * @param string $nome
  * @param string $email
  */
 public function setFrom($nome, $email)
 {
     $this->SMTP->SetFrom($this->SMTP->Username, $nome);
     $this->SMTP->clearReplyTos();
     $this->SMTP->AddReplyTo($email, $nome);
 }
Esempio n. 7
-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;
 }