'', 'port' => '', 'username' => '', 'password' => '' ); public function __construct( $config = null) { if( !$config ) { require_once ( ROOT.'/header.inc.php' ); $boemailadmin = CreateObject('emailadmin.bo'); $emailadmin = $boemailadmin->getProfileList(); $emailadmin = $boemailadmin->getProfile($emailadmin[0]['profileID']); self::$configuration['host'] = $emailadmin['smtpServer']; self::$configuration['port'] = $emailadmin['smtpPort']; // self::$configuration['username'] = $emailadmin['user']; // self::$configuration['password'] = $emailadmin['pass']; // self::$configuration['name'] = $emailadmin['name']; // self::$configuration['type'] = 'SMTP'; // array_merge( $configuration, array( 'auth' => 'login' ) ); zend_include( 'Zend/Mail/Transport/Smtp.php' ); zend_include( 'Zend/Mail/Part.php' ); set_include_path(LIBRARY); parent::setDefaultTransport( new Zend_Mail_Transport_Smtp( self::$configuration['host'], self::$configuration ) ); restore_include_path(); } else $this->configure( $config ); } public function send( $to, $from, $subject, $body, $bcc = null, $cc = null, $isHTML = true ) { set_include_path( LIBRARY ); if( $body ) { if( $isHTML ) parent::setBodyHtml( $body ); else parent::setBodyText( $body ); } if( $subject ) parent::setSubject( $subject ); if( !$from ) $from = $GLOBALS['phpgw']->preferences->values['email']; parent::setFrom( $from, self::getNameByMail( $from ) ); //pra nao ter que fazer os ifs acima... $destTypes = array( 'to', 'bcc', 'cc' ); foreach( $destTypes as $destination ) { $dest = $$destination; if( $dest ) { if( !is_array( $dest ) ) $dest = array( $dest ); foreach( $dest as $d ) { $addDestination = 'add'.ucfirst($destination); parent::$addDestination( $d, self::getNameByMail( $d ) ); } } } parent::send(); restore_include_path(); } public function configure( $config ) { if( !$config ) return( false ); foreach( $config as $key => $value ) { if( $value && isset( self::$configuration[$key] ) ) { self::$configuration[$key] = $value; } } } //hook public function getNameByMail( $mail ) { return( null ); } public function getAttachment( $attachment ) { return( null ); } /** * Adds attachment to the mail message * * @param string $file binary file * @param string $filename file name * @param string $type type example: image/gif * @param Zend_Mime $disposition example: Zend_Mime::DISPOSITION_INLINE * @param Zend_Mime $encoding example: Zend_Mime::ENCODING_BASE64 * @return bool */ public function addAttachment($file, $filename, $type, $encoding = null, $disposition = 'DISPOSITION_ATTACHMENT') { $part = new Zend_Mime_Part( $file ); $part->type = $type; $part->filename = $filename; switch ($disposition) { case 'DISPOSITION_INLINE': $part->disposition = Zend_Mime::DISPOSITION_INLINE; break; case 'DISPOSITION_ATTACHMENT': $part->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; break; default: break; } switch ($encoding) { case 'ENCODING_7BIT': $part->encoding = Zend_Mime::ENCODING_7BIT; break; case 'ENCODING_8BIT:': $part->encoding = Zend_Mime::ENCODING_8BIT; break; case 'ENCODING_QUOTEDPRINTABLE:': $part->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE; break; default: $part->encoding = Zend_Mime::ENCODING_BASE64; break; } parent::addAttachment( $part ); return; } } ServiceLocator::register( 'mail', new MailService() );