[5341] | 1 | <?php |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | class SMTP { |
---|
| 6 | |
---|
| 7 | var $smtp; |
---|
| 8 | var $config; |
---|
| 9 | var $mail; |
---|
| 10 | |
---|
| 11 | public function SMTP(){ |
---|
| 12 | |
---|
| 13 | @session_start(); |
---|
| 14 | $_SESSION['rootPath'] = ROOTPATH .'/../'; |
---|
| 15 | |
---|
| 16 | require_once ( ROOTPATH.'/../library/mime/mimePart.php' ); |
---|
| 17 | require_once ( ROOTPATH.'/../library/mime/mime.php' ); |
---|
| 18 | require_once ( ROOTPATH.'/../library/Mail/Mail.php'); |
---|
| 19 | |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public function find ( $uri, $justthese = false, $criteria = false ){} |
---|
| 23 | |
---|
| 24 | public function read ( $uri, $justthese = false/*, $criteria = false*/ ){} |
---|
| 25 | |
---|
| 26 | //--------------- |
---|
| 27 | |
---|
| 28 | public function deleteAll( $uri, $justthese = false, $criteria = false ){} |
---|
| 29 | |
---|
| 30 | public function delete ( $uri, $justthese = false/*, $criteria = false*/ ){}// avaliar |
---|
| 31 | |
---|
| 32 | //--------------- |
---|
| 33 | |
---|
| 34 | public function replace ( $uri, $data, $criteria = false ){} |
---|
| 35 | |
---|
| 36 | public function update ( $uri, $data/*, $criteria = false*/ ){} |
---|
| 37 | |
---|
| 38 | //--------------- |
---|
| 39 | |
---|
| 40 | public function create ( $uri, $data/*, $criteria = false*/ ) |
---|
| 41 | { |
---|
| 42 | |
---|
| 43 | $this->mail = new Mail_mime(array('html_charset' => 'UTF-8')); |
---|
| 44 | |
---|
| 45 | if( isset($data['body']) ) |
---|
| 46 | { |
---|
| 47 | if( isset($data['isHtml']) && $data['isHtml'] == true ) $this->mail->setHTMLBody( $data['body'] ); |
---|
| 48 | else $this->mail->setTXTBody( $data['body'] ); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | if( isset($data['subject']) ) $this->mail->setSubject ( mb_convert_encoding($data['subject'] , 'ISO-8859-1' , 'UTF-8,ISO-8859-1') ); |
---|
| 52 | |
---|
| 53 | if( isset($data['attachments']) ){ |
---|
| 54 | |
---|
| 55 | foreach ($data['attachments'] as $attachment) |
---|
| 56 | { |
---|
| 57 | if(!isset($attachment['encode'])) |
---|
| 58 | $attachment['encode'] = 'base64'; |
---|
| 59 | if(!isset($attachment['disposition'])) |
---|
| 60 | $attachment['disposition'] = 'attachment'; |
---|
| 61 | |
---|
| 62 | $this->mail->addAttachment($attachment['source'], $attachment['type'], $attachment['name'], false, $attachment['encode'], $attachment['disposition'] , '' , '' , '' , 'base64'); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if( !isset($data['from']) ) $data['from'] = $this->config['email']; |
---|
| 68 | |
---|
| 69 | $this->mail->setFrom( $data['from'] ); |
---|
| 70 | |
---|
| 71 | $this->mail->addTo($data['to']); |
---|
| 72 | |
---|
| 73 | if( isset($data['bcc']) ) $this->mail->addBcc ($data['bcc']); |
---|
| 74 | |
---|
| 75 | if( isset($data['cc']) ) $this->mail->addCc ($data['cc']); |
---|
| 76 | |
---|
| 77 | if(!isset($data['headersFields'])) |
---|
| 78 | $data['headersFields'] = array(); |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | $hdrs = $this->mail->headers($data['headersFields']); |
---|
| 82 | |
---|
| 83 | $recipients = ''; |
---|
| 84 | |
---|
| 85 | if( isset($hdrs["To"]) ) |
---|
| 86 | $recipients .= $hdrs["To"]; |
---|
| 87 | if( isset($hdrs["Cc"]) && $recipients) |
---|
| 88 | $recipients .= ', '.$hdrs["Cc"]; |
---|
| 89 | if( isset($hdrs["Cc"]) && !$recipients) |
---|
| 90 | $recipients = $hdrs["Cc"]; |
---|
| 91 | |
---|
| 92 | if( isset($hdrs["Bcc"])) |
---|
| 93 | $arrayBcc = explode(',',$hdrs["Bcc"]); |
---|
| 94 | |
---|
| 95 | if($recipients) |
---|
| 96 | $sent = $this->smtp->send($recipients, $hdrs , $this->mail->getMessageBody()); |
---|
| 97 | |
---|
| 98 | if(isset($arrayBcc)){ |
---|
| 99 | foreach ($arrayBcc as $bcc) |
---|
| 100 | if($bcc) |
---|
| 101 | $sent = $this->smtp->send($bcc, $hdrs , $this->mail->getMessageBody()); |
---|
| 102 | } |
---|
| 103 | if($sent !== true) |
---|
| 104 | return $sent->message; |
---|
| 105 | |
---|
| 106 | return true; |
---|
| 107 | } |
---|
| 108 | //--------------- |
---|
| 109 | |
---|
| 110 | public function open ( $config ) |
---|
| 111 | { |
---|
| 112 | $this->config = $config; |
---|
| 113 | $this->smtp =& Mail::factory( "smtp" , $config ); |
---|
| 114 | |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | public function close(){} |
---|
| 118 | |
---|
| 119 | public function begin(){} |
---|
| 120 | |
---|
| 121 | public function commit(){} |
---|
| 122 | |
---|
| 123 | public function rollback(){} |
---|
| 124 | |
---|
| 125 | public function setup(){} |
---|
| 126 | |
---|
| 127 | public function teardown(){} |
---|
| 128 | |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | ?> |
---|