Location: PHPKode > projects > Myphpim > MyPhPim-01.05/includes/socket_cl.inc
<?php

//****************************************************************************************
//                Copyright (C) 2000 Koen de Boeve
//
//        This program is free software; you can redistribute it and/or
//        modify it under the terms of the GNU General Public License
//        as published by the Free Software Foundation; either version 2
//        of the License, or (at your option) any later version.
//
//        This program is distributed in the hope that it will be useful,
//        but WITHOUT ANY WARRANTY; without even the implied warranty of
//        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//        GNU General Public License for more details.
//
//        You should have received a copy of the GNU General Public License
//        along with this program; if not, write to the Free Software
//        Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//        Version : MyPhPim-01.05
//        Author : Koen de Boeve
//        Contact: hide@address.com
//**************************************************************************************** 
if ( file_exists ( "conf" ) ) { $conf = "conf"; }
if ( file_exists ( "../conf" ) ) { $conf = "../conf"; }
include $conf . "/imap_conf.inc";
	
Class SocketCl {
	

	Function sendmessage ( $to, $header, $body ) {
		global $config;
		$server = $config[smtphost];
		$serverport = $config[smtpport];
		$domain = $config[domain];
		$headerstr = explode ( "\r\n", $header );
		$ret = FALSE;
		$outheader;
		$num = 0;
		
		$smtp[$num] = array ( "", "220" ); $num++;
		$smtp[$num] = array ( "HELO $domain", "250" ); $num++;
		$smtp[$num] = array ( "MAIL FROM:<$to>","250" ); $num++;
	
		for ( $i = 0; $i <  ( count ( $headerstr ) - 1 ); $i++ ) {
			$head = explode ( ": ", $headerstr[$i] );
			switch ( strtoupper ( $head[0] ) ) {
				case "TO": 
				case "CC": 
					$outheader[count($outheader)] = $headerstr[$i];
				case "BCC":
					$head[1] = str_replace ( "\r", "", $head[1] );
					$parse = imap_rfc822_parse_adrlist ( $head[1] , "");
					
					for( $k = 0; $k < count( $parse ); $k++ ) {
						$smtp[$num] = array ( "RCPT TO:" . $parse[$k]->mailbox . "@" . $parse[$k]->host, "250" ); $num++;
					}
					break;;
				default :
					if ( $head[1] ) {
						$outheader[count($outheader)] = $head[0] . ":" . $head[1];
					} else {
						$outheader[count($outheader)] = $head[0];
					}
						
			}
		}
		$smtp[$num] = array ( "DATA", "354" ); $num++;
		$smtp[$num] = array ( implode ( "\r\n", $outheader ) . "\r\n" . $body . "\r\n.", "250" ); $num++;
		$smtp[$num] = array( "QUIT", "" ); $num++;
		
		if( !$server ) { $server = "localhost"; }
        	if( !$serverport ) { $serverport = "25"; }			

		$connect = fsockopen ( $server, $serverport, &$errno, &$errstr );

		if ( $connect != FALSE ) {
			$ret = $this->ParseCommands ( $connect, $smtp );
			fclose ( $connect );
		}
		return $ret;
	}

	Function ParseCommands ( $conn, $commands ) {
		$sumcom = count ( $commands );
		for ( $i = 0; $i < $sumcom; $i++ ) {
			if ( $commands[$i][0] ) { fwrite ( $conn, $commands[$i][0] . "\r\n" ); }
			if ( $commands[$i][1] ) {
				$chr = "";
                                $rstring = "";
                                while( ord( $chr ) != 10 ) {
                                        $rstring .= $chr;
                                        $chr = fgetc( $conn );
				}
				if ( substr ( $rstring, 0, strlen ( $commands[$i][1] ) ) != $commands[$i][1] ) {
					echo "failed!"; return $rstring;
				}
			} 
		}
		return TRUE;
	} 

}

?>
Return current item: Myphpim