Overview

Namespaces

  • Fabian
    • Mandrill
  • PHP

Classes

  • MandrillMailer
  • Message

Exceptions

  • MandrillException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Fabian\Mandrill;
  4: 
  5: /**
  6:  * Provides similar API to Nette\Mail\Message 
  7:  */
  8: class Message extends \Nette\Mail\Message {
  9:     /**
 10:      * Message parameters
 11:      * @var array
 12:      */
 13:     private $mandrillParams = array();
 14: 
 15:     /**
 16:     * Sets the sender of the message.
 17:     * @param  string  email or format "John Doe" <doe@example.com>
 18:     * @param  string
 19:     * @return Message  provides a fluent interface
 20:     */
 21:     public function setFrom($email, $name = NULL)
 22:     {
 23:         $this->mandrillParams['from_email'] = $email;
 24:         if (!is_null($name)) {
 25:             $this->mandrillParams['from_name'] = $name;
 26:         }
 27:         
 28:         return $this;
 29:     }
 30: 
 31:     /**
 32:     * Sets textual body.
 33:     * @param  string
 34:     * @return Message  provides a fluent interface
 35:     */
 36:     public function setBody($body)
 37:     {
 38:         $this->mandrillParams['text'] = $body;
 39:         
 40:         return $this;
 41:     }
 42:     
 43:     /**
 44:     * Sets HTML body.
 45:     * @param  string
 46:     * @param  NOT IMPLEMENTED
 47:     * @return Message  provides a fluent interface
 48:     */
 49:     public function setHtmlBody($html, $basePath = NULL)
 50:     {
 51:         $this->mandrillParams['html'] = $html;
 52:         
 53:         return $this;
 54:     }
 55:     
 56:     /**
 57:     * Sets the subject of the message.
 58:     * @param  string
 59:     * @return Message  provides a fluent interface
 60:     */
 61:     public function setSubject($subject)
 62:     {
 63:         $this->mandrillParams['subject'] = $subject;
 64:         
 65:         return $this;
 66:     }
 67:     
 68:     /**
 69:     * Adds email recipient.
 70:     * @param  string  email or format "John Doe" <doe@example.com>
 71:     * @param  string
 72:     * @return Message  provides a fluent interface
 73:     */
 74:     public function addTo($email, $name = NULL)
 75:     {
 76:         if (!isset($this->mandrillParams['to'])) {
 77:             $this->mandrillParams['to'] = array();
 78:         }
 79:         $recipient = array('email' => $email);
 80:         if (!is_null($name)) {
 81:             $recipient['name'] = $name;
 82:         }
 83:         $this->mandrillParams['to'][] = $recipient;
 84:         
 85:         return $this;
 86:     }
 87:     
 88:     /**
 89:      * Add tag form Mandrill Outbound info
 90:      * @param string $tag
 91:      * @return Message  provides a fluent interface
 92:      */
 93:     public function addTag($tag)
 94:     {
 95:         if (!isset($this->mandrillParams['tags'])) {
 96:             $this->mandrillParams['tags'] = array();
 97:         }
 98:         $this->mandrillParams['tags'][] = $tag;
 99:         
100:         return $this;
101:     }
102:     
103:     /**
104:      * Enable a background sending mode that is optimized for bulk sending. In async mode, messages/send will immediately return a status of "queued" for every recipient. To handle rejections when sending in async mode, set up a webhook for the 'reject' event. Defaults to false for messages with no more than 10 recipients; messages with more than 10 recipients are always sent asynchronously, regardless of the value of async.
105:      * @param type $async 
106:      * @return Message  provides a fluent interface
107:      */
108:     public function setAsync($async = TRUE)
109:     {
110:         $this->mandrillParams['async'] = $async;
111:         
112:         return $this;
113:     }
114:     
115:     /**
116:      * Add another Mandrill param
117:      * @param string $param
118:      * @param string $value
119:      * @return Message  provides a fluent interface
120:      */
121:     public function setParam($param, $value)
122:     {
123:         $this->mandrillParams[$param] = $value;
124:         
125:         return $this;
126:     }
127:     
128:     /**
129:      * Returns Mandrill params
130:      * @return array
131:      */
132:     public function getMandrillParams()
133:     {
134:         return $this->mandrillParams;
135:     }
136: }
API documentation generated by ApiGen 2.8.0