setMessageId() публичный Метод

Sets the Message-ID of the message
public setMessageId ( boolean | string $id = true ) : Zend_Mail
$id boolean | string true :Auto false :No set null :No set string:Sets given string (Angle brackets is not necessary)
Результат Zend_Mail Provides fluent interface
Пример #1
0
 public function indexAction()
 {
     $req = $this->getRequest();
     $this->view->form = new Group_Form_Contact('contact');
     if ($req->isPost()) {
         if ($this->view->form->isValid($_POST)) {
             // we need the email settings from the registry
             $this->mailsettings = Zend_Registry::get('emailSettings');
             $values = $this->view->form->getValues();
             if (!$this->mailsettings->sendmail) {
                 $mtconf = array('auth' => 'login', 'username' => $this->mailsettings->smtp->user, 'password' => $this->mailsettings->smtp->password, 'port' => $this->mailsettings->smtp->port);
                 if ($this->mailsettings->smtp->ssl) {
                     $mtconf['ssl'] = 'tls';
                 }
                 $mtr = new Zend_Mail_Transport_Smtp($this->mailsettings->smtp->host, $mtconf);
             } else {
                 $mtr = new Zend_Mail_Sendmail();
             }
             $mailer = new Zend_Mail('UTF-8');
             $mailer->setFrom($values['email'], $values['author']);
             $mailer->addTo($this->mailsettings->email->admin, 'FansubCMS Administration');
             $mailer->setMessageId();
             $mailer->setSubject('FansubCMS Contact');
             $mailer->addHeader('X-MailGenerator', 'ContactForm on FansubCMS');
             $mailer->addHeader('X-Mailer', 'FansubCMS');
             $mailer->addHeader('X-Priority', '3');
             $message = $this->translate('contact_mail_text', array('name' => $values['author'], 'email' => $values['email'], 'text' => $values['content']));
             $mailer->setBodyText($message, 'UTF-8');
             if ($mailer->send($mtr)) {
                 $this->view->message = $this->translate('group_contact_mail_sent_successful');
                 $this->view->form = new Group_Form_Contact('contact');
             }
         }
     }
     $this->view->title = $this->translate('group_contact_title');
 }
 /**
  * set headers in mail to be sent
  * 
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Account $_account
  * @param Felamimail_Model_Message $_message
  */
 protected function _setMailHeaders(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = NULL)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting mail headers');
     }
     // add user agent
     $_mail->addHeader('User-Agent', 'Tine 2.0 Email Client (version ' . TINE20_CODENAME . ' - ' . TINE20_PACKAGESTRING . ')');
     // set organization
     if (isset($_account->organization) && !empty($_account->organization)) {
         $_mail->addHeader('Organization', $_account->organization);
     }
     // set message-id (we could use Zend_Mail::createMessageId() here)
     if ($_mail->getMessageId() === NULL) {
         $domainPart = substr($_account->email, strpos($_account->email, '@'));
         $uid = Tinebase_Record_Abstract::generateUID();
         $_mail->setMessageId('<' . $uid . $domainPart . '>');
     }
     if ($_message !== NULL) {
         if ($_message->flags && $_message->flags == Zend_Mail_Storage::FLAG_ANSWERED && $_message->original_id instanceof Felamimail_Model_Message) {
             $this->_addReplyHeaders($_message);
         }
         // set the header request response
         if ($_message->reading_conf) {
             $_mail->addHeader('Disposition-Notification-To', $_message->from_email);
         }
         // add other headers
         if (!empty($_message->headers) && is_array($_message->headers)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding custom headers: ' . print_r($_message->headers, TRUE));
             }
             foreach ($_message->headers as $key => $value) {
                 $value = $this->_trimHeader($key, $value);
                 $_mail->addHeader($key, $value);
             }
         }
     }
 }
Пример #3
0
 protected function _sendEmail(array $email, array $user, Zend_Mail_Transport_Abstract $transport)
 {
     if (!$user['email']) {
         return;
     }
     $phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
     /** @var XenForo_Model_Phrase $phraseModel */
     $phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
     $phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
     foreach ($phraseTitles as $search => $phraseTitle) {
         if (isset($phrases[$phraseTitle])) {
             $email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
             $email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
         }
     }
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
     $options = XenForo_Application::getOptions();
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $toEmail = $user['email'];
     $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
     $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
     if ($options->enableVerp) {
         $verpValue = str_replace('@', '=', $toEmail);
         $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     if ($email['email_format'] == 'html') {
         $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
         $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
     } else {
         $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $mailObj->setBodyText($email['email_body']);
     }
     if (!$mailObj->getMessageId()) {
         $mailObj->setMessageId();
     }
     $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
     try {
         $mailObj->send($thisTransport);
     } catch (Exception $e) {
         if (method_exists($thisTransport, 'resetConnection')) {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
             $thisTransport->resetConnection();
             try {
                 $mailObj->send($thisTransport);
             } catch (Exception $e) {
                 XenForo_Error::logException($e, false, "Email to {$user['email']} failed (after retry): ");
             }
         } else {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
         }
     }
 }
Пример #4
0
 protected function _sendEmail(array $user, array $email, Zend_Mail_Transport_Abstract $transport)
 {
     if (!$user['email']) {
         return false;
     }
     if (!XenForo_Application::get('config')->enableMail) {
         return true;
     }
     $options = XenForo_Application::getOptions();
     XenForo_Db::ping();
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $toEmail = $user['email'];
     $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
     $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
     if ($options->enableVerp) {
         $verpValue = str_replace('@', '=', $toEmail);
         $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     if ($email['email_format'] == 'html') {
         $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
         $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
     } else {
         $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $mailObj->setBodyText($email['email_body']);
     }
     if (!$mailObj->getMessageId()) {
         $mailObj->setMessageId();
     }
     $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
     try {
         $mailObj->send($thisTransport);
     } catch (Exception $e) {
         XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
         return false;
     }
     return true;
 }
Пример #5
0
 public function testClearMessageId()
 {
     $mail = new Zend_Mail();
     $mail->setMessageId();
     $mail->clearMessageId();
     $this->assertFalse(isset($mock->headers['Message-Id']));
 }
Пример #6
0
 /**
  * Gets the fully prepared, internal mail object. This can be called directly
  * to allow advanced manipulation before sending
  *
  * @param string $toEmail The email address the email is sent to
  * @param string $toName Name of the person receiving it
  * @param array $headers List of additional headers to send
  * @param string $fromEmail Email address the email should come from; if not specified, uses board default
  * @param string $fromName Name the email should come from; if not specified, uses board default
  * @param string $returnPath The return path of the email (where bounces should go to)
  *
  * @return Zend_Mail|false
  */
 public function getPreparedMailHandler($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
 {
     if (!$toEmail) {
         return false;
     }
     $contents = $this->prepareMailContents();
     if (!$contents) {
         return false;
     }
     $contents = $this->wrapMailContainer($contents['subject'], $contents['bodyText'], $contents['bodyHtml']);
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($contents['subject'])->setBodyText($contents['bodyText'])->addTo($toEmail, $toName);
     if ($contents['bodyHtml'] !== '') {
         $mailObj->setBodyHtml($contents['bodyHtml']);
     }
     $options = XenForo_Application::getOptions();
     if (!$fromName) {
         $fromName = $options->emailSenderName ? $options->emailSenderName : $options->boardTitle;
     }
     if ($fromEmail) {
         $mailObj->setFrom($fromEmail, $fromName);
     } else {
         $mailObj->setFrom($options->defaultEmailAddress, $fromName);
     }
     if ($returnPath) {
         $mailObj->setReturnPath($returnPath);
     } else {
         $bounceEmailAddress = $options->bounceEmailAddress;
         if (!$bounceEmailAddress) {
             $bounceEmailAddress = $options->defaultEmailAddress;
         }
         $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
         $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
         if ($options->enableVerp) {
             $verpValue = str_replace('@', '=', $toEmail);
             $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
         }
         $mailObj->setReturnPath($bounceEmailAddress);
     }
     foreach ($headers as $headerName => $headerValue) {
         if (isset(self::$_headerMap[strtolower($headerName)])) {
             $func = self::$_headerMap[strtolower($headerName)];
             $mailObj->{$func}($headerValue);
         } else {
             $mailObj->addHeader($headerName, $headerValue);
         }
     }
     if (!$mailObj->getMessageId()) {
         $mailObj->setMessageId();
     }
     return $mailObj;
 }
 /**
  * send message using default transport or an instance of Zend_Mail_Transport_Abstract
  *
  * @param Zend_Mail $_mail
  * @param Zend_Mail_Transport_Abstract $_transport
  * @return void
  */
 public function sendMessage(Zend_Mail $_mail, $_transport = NULL)
 {
     $transport = $_transport instanceof Zend_Mail_Transport_Abstract ? $_transport : self::getDefaultTransport();
     if (!$_mail->getMessageId()) {
         $_mail->setMessageId();
     }
     $_mail->addHeader('X-MailGenerator', 'Tine 2.0');
     $_mail->send($transport);
 }
Пример #8
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('start' => 0, 'count' => 0, 'criteria' => null, 'userIds' => null, 'email' => array()), $data);
     if (!XenForo_Application::get('config')->enableMail) {
         return false;
     }
     $s = microtime(true);
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     if (is_array($data['criteria'])) {
         $userIds = $userModel->getUserIds($data['criteria'], $data['start'], 1000);
     } else {
         if (is_array($data['userIds'])) {
             $userIds = $data['userIds'];
         } else {
             $userIds = array();
         }
     }
     if (!$userIds) {
         return false;
     }
     $options = XenForo_Application::getOptions();
     $email = $data['email'];
     $transport = XenForo_Mail::getTransport();
     $limitTime = $targetRunTime > 0;
     foreach ($userIds as $key => $userId) {
         $data['count']++;
         $data['start'] = $userId;
         unset($userIds[$key]);
         $user = $userModel->getUserById($userId);
         if (!$user['email']) {
             continue;
         }
         $phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
         /** @var XenForo_Model_Phrase $phraseModel */
         $phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
         $phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
         foreach ($phraseTitles as $search => $phraseTitle) {
             if (isset($phrases[$phraseTitle])) {
                 $email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
                 $email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
             }
         }
         $mailObj = new Zend_Mail('utf-8');
         $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
         $bounceEmailAddress = $options->bounceEmailAddress;
         if (!$bounceEmailAddress) {
             $bounceEmailAddress = $options->defaultEmailAddress;
         }
         $toEmail = $user['email'];
         $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
         $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
         if ($options->enableVerp) {
             $verpValue = str_replace('@', '=', $toEmail);
             $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
         }
         $mailObj->setReturnPath($bounceEmailAddress);
         if ($email['email_format'] == 'html') {
             $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
             $email['email_body'] = strtr($email['email_body'], $replacements);
             $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
             $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
         } else {
             $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
             $email['email_body'] = strtr($email['email_body'], $replacements);
             $mailObj->setBodyText($email['email_body']);
         }
         if (!$mailObj->getMessageId()) {
             $mailObj->setMessageId();
         }
         $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
         try {
             $mailObj->send($thisTransport);
         } catch (Exception $e) {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
             continue;
         }
         if ($limitTime && microtime(true) - $s > $targetRunTime) {
             break;
         }
     }
     if (is_array($data['userIds'])) {
         $data['userIds'] = $userIds;
     }
     $actionPhrase = new XenForo_Phrase('emailing');
     $typePhrase = new XenForo_Phrase('users');
     $status = sprintf('%s... %s (%d)', $actionPhrase, $typePhrase, $data['count']);
     return $data;
 }
Пример #9
0
 /**
  * Create zend mail object for sending out
  * the email
  * 
  * @return Zend_Mail
  */
 public function createMailObject()
 {
     $sender = $this->getCampaign()->getSender();
     $recipient = $this->getRecipient();
     $recipient->prepare();
     $mail = new Zend_Mail('utf-8');
     $mail->setSubject($this->getSubject());
     $mail->addTo($recipient->getAddress(), '=?utf-8?B?' . base64_encode($recipient->getName()) . '?=');
     $mail->setMessageId($this->getMessageId());
     $mail->setBodyText($this->getBodyText());
     $mail->setBodyHtml($this->getBodyHtml());
     $mail->setFrom($sender['email'], $sender['name']);
     $mail->addHeader('X-Mailer', 'Mzax-Emarketing ' . Mage::helper('mzax_emarketing')->getVersion());
     $mail->addHeader('X-Mailer-Version', Mage::helper('mzax_emarketing')->getVersion());
     $mail->addHeader('X-Originating-IP', Mage::app()->getRequest()->getServer('SERVER_ADDR'));
     // Add List-Unsubscribe
     if (Mage::getStoreConfigFlag('mzax_emarketing/email/list_unsubscribe', $recipient->getStoreId())) {
         $unsubscribe = array();
         $address = Mage::getStoreConfig('mzax_emarketing/email/list_unsubscribe_address', $recipient->getStoreId());
         if ($address) {
             $unsubscribe[] = "mailto:{$address}?subject=Unsubscribe%20{$recipient->getAddress()}%20({$recipient->getBeaconHash()})";
         }
         foreach ($unsubscribe as &$value) {
             $value = "<{$value}>";
         }
         $unsubscribe[] = $recipient->getUrl('mzax_emarketing/unsubscribe/list', array('id' => $recipient->getBeaconHash()));
         $mail->addHeader('List-Unsubscribe', implode(',', $unsubscribe));
     }
     $this->setCancelEmail(false);
     Mage::dispatchEvent('mzax_emarketing_create_mail_object', array('mail' => $mail, 'recipient' => $recipient, 'outbox_email' => $this));
     if ($this->getCancelEmail()) {
         return null;
     }
     if (Mage::getStoreConfigFlag('mzax_emarketing/email/test_mode', $recipient->getStoreId())) {
         $address = Mage::getStoreConfig('mzax_emarketing/email/test_mode_address', $recipient->getStoreId());
         if (!$address) {
             return null;
         }
         $mail->clearRecipients();
         $mail->addTo($address);
     }
     return $mail;
 }