Overview

Packages

  • Onion::Controllers
  • Onion::Core
  • Onion::UI
  • Onion::Utils

Classes

  • Arrays
  • Assets
  • Filesystem
  • Image
  • Languages
  • Mail
  • Secure
  • Strings
  • SWF
  • Utils
  • Validate
  • Visitor
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * Onion Framework - Odosielanie e-mailov
 5:  *
 6:  * Copyright (c) 2011 Jano Gašpar (http://webstranky.net)
 7:  *
 8:  * @author    Jano Gašpar
 9:  * @copyright Copyright (c) 2011 Jano Gašpar
10:  * @package   Onion::Utils
11:  **/
12: 
13: class Mail {
14:     public $address = NULL;
15:     public $subject = '';
16:     public $message = '';
17:     public $htmlMessage = '';
18:     public $nameTo = 'owner';
19:     public $from = 'mail@example.com';
20:     public $nameFrom = 'web';
21: 
22:     public $bcc = array();
23:     public $cc = array();
24: 
25:     public $attachment = NULL;
26: 
27: 
28:     function send() {
29:         $mail = new PHPMailer();
30:         $mail->IsMail();
31: 
32:         try {
33:             $mail->SetFrom($this->from, $this->nameFrom);
34:             if (is_array($this->address) == TRUE) {
35:                 foreach ($this->address as $address) {
36:                     $mail->AddAddress($address);
37:                 }
38: 
39:             } else {
40:                 $mail->AddAddress($this->address);
41:             }
42: 
43:             $mail->CharSet = 'utf-8';
44: 
45:             if (empty($this->bcc) == FALSE) {
46:                 foreach ($this->bcc as $address) {
47:                     $mail->AddBCC($address);
48:                 }
49:             }
50: 
51:             if (empty($this->cc) == FALSE) {
52:                 foreach ($this->cc as $address) {
53:                     $mail->AddCC($address);
54:                 }
55:             }
56: 
57:             $message = explode(chr(10), $this->message);
58:             foreach ($message as $index => $line) {
59:                 $message[$index] = Strings::wordwrap($line, 72, chr(10));
60:             }
61:             $message = implode(chr(10), $message);
62: 
63:             $mail->Subject = $this->subject;
64:             $mail->AltBody = $message;
65: 
66:             if (empty($this->htmlMessage) == FALSE) {
67:                 $mail->MsgHTML($this->htmlMessage);
68: 
69:             } else {
70:                 $mail->MsgHTML('<pre>'.$message.'</pre>');
71:             }
72: 
73:             if (empty($this->attachment) == FALSE) {
74:                 if (is_array($this->attachment) == TRUE) {
75:                     foreach ($this->attachment as $name => $file) {
76:                         if (is_numeric($name) == TRUE) {
77:                             $name = $file;
78:                         }
79: 
80:                         $mail->AddAttachment($file, $name);
81:                     }
82: 
83:                 } else {
84:                     $mail->AddAttachment($this->attachment);
85:                 }
86:             }
87: 
88:             $mail->Send();
89: 
90:             return TRUE;
91: 
92:         } catch (Exception $e) {
93:             echo $e->getMessage();
94:             return FALSE;
95:         }
96:     }
97: }
98: 
Onion API documentation generated by ApiGen.
Generated using the TokenReflection library.