/** * Clears the default ReplyTo-address and -name from the mail * * @return void */ public static function clearDefaultReplyTo() { self::$_defaultReplyTo = null; }
/** * Get the sender from PostmanMessage and add it to the Postman_Zend_Mail object * * @param PostmanMessage $message * @param Postman_Zend_Mail $mail * @return PostmanEmailAddress */ public function addFrom(PostmanMessage $message, Postman_Zend_Mail $mail) { $sender = $message->getFromAddress(); // now log it and push it into the message $senderEmail = $sender->getEmail(); $senderName = $sender->getName(); assert(!empty($senderEmail)); if (!empty($senderName)) { $mail->setFrom($senderEmail, $senderName); } else { $mail->setFrom($senderEmail); } return $sender; }
/** * Send a mail using this transport * * @param Postman_Zend_Mail $mail * @access public * @return void * @throws Postman_Zend_Mail_Transport_Exception if mail is empty */ public function send(Postman_Zend_Mail $mail) { $this->_isMultipart = false; $this->_mail = $mail; $this->_parts = $mail->getParts(); $mime = $mail->getMime(); // Build body content $this->_buildBody(); // Determine number of parts and boundary $count = count($this->_parts); $boundary = null; if ($count < 1) { /** * @see Postman_Zend_Mail_Transport_Exception */ require_once 'Exception.php'; throw new Postman_Zend_Mail_Transport_Exception('Empty mail cannot be sent'); } if ($count > 1) { // Multipart message; create new MIME object and boundary $mime = new Postman_Zend_Mime($this->_mail->getMimeBoundary()); $boundary = $mime->boundary(); } elseif ($this->_isMultipart) { // multipart/alternative -- grab boundary $boundary = $this->_parts[0]->boundary; } // Determine recipients, and prepare headers $this->recipients = implode(',', $mail->getRecipients()); $this->_prepareHeaders($this->_getHeaders($boundary)); // Create message body // This is done so that the same Postman_Zend_Mail object can be used in // multiple transports $message = new Postman_Zend_Mime_Message(); $message->setParts($this->_parts); $message->setMime($mime); $this->body = $message->generateMessage($this->EOL); // Send to transport! $this->_sendMail(); }
/** * Add attachments to the message * * @param Postman_Zend_Mail $mail */ public function addAttachmentsToMail(Postman_Zend_Mail $mail) { $attachments = $this->attachments; if (!is_array($attachments)) { // WordPress may a single filename or a newline-delimited string list of multiple filenames $attArray = explode(PHP_EOL, $attachments); } else { $attArray = $attachments; } // otherwise WordPress sends an array foreach ($attArray as $file) { if (!empty($file)) { $this->logger->debug("Adding attachment: " . $file); $at = new Postman_Zend_Mime_Part(file_get_contents($file)); // $at->type = 'image/gif'; $at->disposition = Postman_Zend_Mime::DISPOSITION_ATTACHMENT; $at->encoding = Postman_Zend_Mime::ENCODING_BASE64; $at->filename = basename($file); $mail->addAttachment($at); } } }