Horde_Mime_Part::send PHP Method

send() public method

Sends this message.
public send ( string $email, Horde_Mime_Headers $headers, Horde_Mail_Transport $mailer, array $opts = [] )
$email string The address list to send to.
$headers Horde_Mime_Headers The Horde_Mime_Headers object holding this message's headers.
$mailer Horde_Mail_Transport A Horde_Mail_Transport object.
$opts array Additional options:
  - broken_rfc2231: (boolean) Attempt to work around non-RFC
                    2231-compliant MUAs by generating both a RFC
                    2047-like parameter name and also the correct RFC
                    2231 parameter (@since 2.5.0).
                    DEFAULT: false
  - encode: (integer) The encoding to use. A mask of self::ENCODE_*
            values.
            DEFAULT: Auto-determined based on transport driver.
    public function send($email, $headers, Horde_Mail_Transport $mailer, array $opts = array())
    {
        $old_status = $this->_status;
        $this->isBasePart(true);
        /* Does the SMTP backend support 8BITMIME (RFC 1652)? */
        $canonical = true;
        $encode = self::ENCODE_7BIT;
        if (isset($opts['encode'])) {
            /* Always allow 7bit encoding. */
            $encode |= $opts['encode'];
        } elseif ($mailer instanceof Horde_Mail_Transport_Smtp) {
            try {
                $smtp_ext = $mailer->getSMTPObject()->getServiceExtensions();
                if (isset($smtp_ext['8BITMIME'])) {
                    $encode |= self::ENCODE_8BIT;
                }
            } catch (Horde_Mail_Exception $e) {
            }
            $canonical = false;
        } elseif ($mailer instanceof Horde_Mail_Transport_Smtphorde) {
            try {
                if ($mailer->getSMTPObject()->data_8bit) {
                    $encode |= self::ENCODE_8BIT;
                }
            } catch (Horde_Mail_Exception $e) {
            }
            $canonical = false;
        }
        $msg = $this->toString(array('canonical' => $canonical, 'encode' => $encode, 'headers' => false, 'stream' => true));
        /* Add MIME Headers if they don't already exist. */
        if (!isset($headers['MIME-Version'])) {
            $headers = $this->addMimeHeaders(array('encode' => $encode, 'headers' => $headers));
        }
        if (!empty($this->_temp['toString'])) {
            $headers->addHeader('Content-Transfer-Encoding', $this->_temp['toString']);
            switch ($this->_temp['toString']) {
                case '8bit':
                    if ($mailer instanceof Horde_Mail_Transport_Smtp) {
                        $mailer->addServiceExtensionParameter('BODY', '8BITMIME');
                    }
                    break;
            }
        }
        $this->_status = $old_status;
        $rfc822 = new Horde_Mail_Rfc822();
        try {
            $mailer->send($rfc822->parseAddressList($email)->writeAddress(array('encode' => $this->getHeaderCharset() ?: true, 'idn' => true)), $headers->toArray(array('broken_rfc2231' => !empty($opts['broken_rfc2231']), 'canonical' => $canonical, 'charset' => $this->getHeaderCharset())), $msg);
        } catch (InvalidArgumentException $e) {
            // Try to rebuild the part in case it was due to
            // an invalid line length in a rfc822/message attachment.
            if ($this->_failed) {
                throw $e;
            }
            $this->_failed = true;
            $this->_sanityCheckRfc822Attachments();
            try {
                $this->send($email, $headers, $mailer, $opts);
            } catch (Horde_Mail_Exception $e) {
                throw new Horde_Mime_Exception($e);
            }
        } catch (Horde_Mail_Exception $e) {
            throw new Horde_Mime_Exception($e);
        }
    }

Usage Example

Example #1
0
 /**
  * Sends a message to an email address supposed to be added to the
  * identity.
  *
  * A message is send to this address containing a time-sensitive link to
  * confirm that the address really belongs to that user.
  *
  * @param integer $id       The identity's ID.
  * @param string $old_addr  The old From: address.
  *
  * @throws Horde_Mime_Exception
  */
 public function verifyIdentity($id, $old_addr)
 {
     global $injector, $notification, $registry;
     $hash = strval(new Horde_Support_Randomid());
     $pref = $this->_confirmEmail();
     $pref[$hash] = $this->get($id);
     $pref[$hash][self::EXPIRE] = time() + self::EXPIRE_SECS;
     $this->_confirmEmail($pref);
     $new_addr = $this->getValue($this->_prefnames['from_addr'], $id);
     $confirm = Horde::url($registry->getServiceLink('emailconfirm')->add('h', $hash)->setRaw(true), true);
     $message = sprintf(Horde_Core_Translation::t("You have requested to add the email address \"%s\" to the list of your personal email addresses.\n\nGo to the following link to confirm that this is really your address:\n%s\n\nIf you don't know what this message means, you can delete it."), $new_addr, $confirm);
     $msg_headers = new Horde_Mime_Headers();
     $msg_headers->addHeaderOb(Horde_Mime_Headers_MessageId::create());
     $msg_headers->addHeaderOb(Horde_Mime_Headers_UserAgent::create());
     $msg_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
     $msg_headers->addHeader('To', $new_addr);
     $msg_headers->addHeader('From', $old_addr);
     $msg_headers->addHeader('Subject', Horde_Core_Translation::t("Confirm new email address"));
     $body = new Horde_Mime_Part();
     $body->setType('text/plain');
     $body->setContents(Horde_String::wrap($message, 76));
     $body->setCharset('UTF-8');
     $body->send($new_addr, $msg_headers, $injector->getInstance('Horde_Mail'));
     $notification->push(sprintf(Horde_Core_Translation::t("A message has been sent to \"%s\" to verify that this is really your address. The new email address is activated as soon as you confirm this message."), $new_addr), 'horde.message');
 }
All Usage Examples Of Horde_Mime_Part::send