/** * @param string $subject * The subject. May contain variable references to memebrs * of the $fields array. * @param string $view * The name of a view * @param array $fields * The fields referenced in the subject and/or view * @param array $optoins * Array of options. Can include: * "html" => Defaults to false. Whether to send as HTML email. * "name" => A human-readable name in addition to the address. * "from" => An array of email_address => human_readable_name */ function sendMessage($subject, $view, $fields = array(), $options = array()) { if (!isset($options['from'])) { $url_parts = parse_url(Pie_Request::baseUrl()); $domain = $url_parts['host']; $options['from'] = array("email_bot@" . $domain => $domain); } else { if (!is_array($options['from'])) { throw new Pie_Exception_WrongType(array('field' => '$options["from"]', 'type' => 'array')); } } // Set up the default mail transport $tr = new Zend_Mail_Transport_Sendmail('-f' . $this->address); Zend_Mail::setDefaultTransport($tr); $mail = new Zend_Mail(); $from_name = reset($options['from']); $mail->setFrom(key($options['from']), $from_name); if (isset($options['name'])) { $mail->addTo($this->address, $options['name']); } else { $mail->addTo($this->address); } $subject = Pie::expandString($subject, $fields); $body = Pie::view($view, $fields); $mail->setSubject($subject); if (empty($options['html'])) { $mail->setBodyText($body); } else { $mail->setBodyHtml($body); } $mail->send(); return true; }
/** * Creates an exception * @param array $params * Optional. Array of parameters for the exception. * Used in the exception message, etc. * To access them later, call $e->params() * You can also provide a string here, which will * then be the exception message. * @param array $input_fields * Optional. Array of names of input fields * to which the exception applies. */ function __construct($params = array(), $input_fields = array()) { if (is_string($input_fields)) { $input_fields = array($input_fields => null); } $this->inputFields = $input_fields; if (is_string($params)) { parent::__construct($params, 0); return; } $this->params = is_array($params) ? $params : array(); $class_name = get_class($this); if (isset(self::$messages[$class_name])) { $t_message = Pie::expandString(self::$messages[$class_name], $this->params); } else { $t_message = $class_name; } if (isset(self::$messages[$class_name])) { $t_code = self::$codes[$class_name]; } else { $t_code = 0; } parent::__construct($t_message, $t_code); }