1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Ulaform_Action_Mailto extends Ulaform_Action {
15:
16: 17: 18:
19: public function doAction($form_params, $form_data, $fields)
20: {
21: global $conf;
22:
23: $mail = new Horde_Mime_Mail();
24: $mail->addHeader('From', $form_params['from']);
25: $mail->addHeader('Subject', $form_params['subject']);
26: $mail->addHeader('To', $form_params['to']);
27: if (!empty($form_params['cc'])) {
28: $mail->addHeader('Cc', $form_params['cc']);
29: }
30: if (!empty($form_params['bcc'])) {
31: $mail->addHeader('Bcc', $form_params['bcc']);
32: }
33:
34: $body = '';
35: foreach ($fields as $field) {
36: $value = array_shift($form_data);
37: switch ($field['field_type']) {
38: case 'file':
39: case 'image':
40: if (!empty($value['file'])) {
41: $mail->addAttachment($value['file'], $value['name'], $value['type']);
42: }
43: break;
44:
45: default:
46: $body .= $field['field_label'] . ': ' .
47: $this->_formatFormData($value) . "\n";
48: break;
49: }
50: }
51:
52: $mail->setBody($body);
53: return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
54: }
55:
56: 57: 58: 59: 60: 61:
62: static public function getInfo()
63: {
64: $info['name'] = _("Mailto");
65: $info['desc'] = _("This driver allows the sending of form results via email to one or more recipients.");
66:
67: return $info;
68: }
69:
70: 71: 72: 73: 74: 75:
76: static public function getParams()
77: {
78: $params = array();
79: $params['subject'] = array('label' => _("Subject"), 'type' => 'text');
80: $params['from'] = array('label' => _("From"), 'type' => 'email');
81: $params['to'] = array('label' => _("To"),
82: 'type' => 'email',
83: 'params' => array(true));
84: $params['cc'] = array('label' => _("Cc"),
85: 'type' => 'email',
86: 'required' => false,
87: 'params' => array(true));
88: $params['bcc'] = array('label' => _("Bcc"),
89: 'type' => 'email',
90: 'required' => false,
91: 'params' => array(true));
92:
93: return $params;
94: }
95:
96: 97: 98: 99: 100: 101:
102: protected function _formatFormData($field_data)
103: {
104: $body = '';
105: if (!is_array($field_data)) {
106: $body = $field_data;
107: } else {
108: foreach ($field_data as $data) {
109: $body .= empty($body) ? $this->_formatFormData($data)
110: : ', ' . $this->_formatFormData($data);
111: }
112: }
113: return $body;
114: }
115:
116: }
117: