Zend_Mail::setType PHP Method

setType() public method

Should only be used for manually setting multipart content types.
public setType ( string $type ) : Zend_Mail
$type string Content type
return Zend_Mail Implements fluent interface
    public function setType($type)
    {
        $allowed = array(Zend_Mime::MULTIPART_ALTERNATIVE, Zend_Mime::MULTIPART_MIXED, Zend_Mime::MULTIPART_RELATED);
        if (!in_array($type, $allowed)) {
            /**
             * @see Zend_Mail_Exception
             */
            require_once 'Zend/Mail/Exception.php';
            throw new Zend_Mail_Exception('Invalid content type "' . $type . '"');
        }
        $this->_type = $type;
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * Send email notification to moderators when a new comment is posted
  * 
  * @todo move logic to model / library class
  * 
  * @param HumanHelp_Model_Comment $comment
  * @param HumanHelp_Model_Page $page
  */
 public function _sendNewCommentEmail(HumanHelp_Model_Comment $comment, HumanHelp_Model_Page $page)
 {
     $config = Zend_Registry::get('config');
     $emailTemplate = new Zend_View();
     $emailTemplate->setScriptPath(APPLICATION_PATH . '/views/emails');
     $emailTemplate->addHelperPath(APPLICATION_PATH . '/views/helpers', 'HumanHelp_View_Helper_');
     $emailTemplate->setEncoding('UTF-8');
     $emailTemplate->comment = $comment;
     $emailTemplate->page = $page;
     $emailTemplate->baseUrl = 'http://' . $_SERVER['HTTP_HOST'] . $this->view->baseUrl;
     $bodyHtml = $emailTemplate->render('newComment.phtml');
     $bodyText = $emailTemplate->render('newComment.ptxt');
     $mail = new Zend_Mail();
     $mail->setType(Zend_Mime::MULTIPART_ALTERNATIVE)->setBodyHtml($bodyHtml, 'UTF-8')->setBodyText($bodyText, 'UTF-8')->setSubject("New comment on '{$page->getTitle()}' in '{$page->getBook()->getTitle()}'")->setFrom($config->fromAddress, $config->fromName);
     if (is_object($config->notifyComments)) {
         foreach ($config->notifyComments->toArray() as $rcpt) {
             $mail->addTo($rcpt);
         }
     } else {
         $mail->addTo($config->notifyComments);
     }
     if ($config->smtpServer) {
         $transport = new Zend_Mail_Transport_Smtp($config->smtpServer, $config->smtpOptions->toArray());
     } else {
         $transport = new Zend_Mail_Transport_Sendmail();
     }
     $mail->send($transport);
 }
All Usage Examples Of Zend_Mail::setType