Hallo,
ich hab zu dem Thema diesen code gefunden:
	
wie baue ich nun das ganze in mein Formular ein? 

LG
Clemens
					ich hab zu dem Thema diesen code gefunden:
PHP-Code:
	
	
der Aufruf
PHP:--------------------------------------------------------------------------------
$smtp = new SMTP( $server, $user_name, $user_pass );
$error = $smtp->send( array( $HTTP_POST_VARS['target'] ), $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['text'] );
if($error)echo$error;
--------------------------------------------------------------------------------
die Klasse
PHP:--------------------------------------------------------------------------------
/**
 * class:         smtp.class.php
 * require:
 * optional:    
 * description:    class for sending mail directly throw an smtp server
 * created:        25.08.2002
 * last change:    18.09.2002
 * author:        Sven Denkert <sven.denkert@t-online.de>
 * copyright:    Sven Denkert
 * 
 * TODO:        MIME / Attachments / error-handling like pop3.class.php
 */
if ( !isset( $_CLASS_SMTP_ ) ) {
    $_CLASS_SMTP_ = 1;
    class SMTP {
        var $server = "";
        var $user_name = "";
        var $user_pass = "";
        var $from = "anonymous@unknown.home";
        var $socket;
        var $error;
        function SMTP( $server, $user_name = null, $user_pass = null )
        {
            if ( !$this->server = $server )
                return $this->error = "No SMTP server provided";
            if ( trim( $user_name ) )
                $this->user_name = trim( $user_name );
            if ( trim( $user_pass ) )
                $this->user_pass = trim( $user_pass );
        } 
        function &server_parse( $response )
        {
            $server_response = "";
            while ( substr( $server_response, 3, 1 ) != ' ' )
            if ( !( $server_response = fgets( $this->socket, 256 ) ) )
                return $this->error = "Couldn't get mail server response codes";
            if ( substr( $server_response, 0, 3 ) != $response )
                return $this->error = "Couldn't not send mail. Server response: $server_response";
            return "";
        } 
        function &put( $string )
        {
            return fputs( $this->socket, $string . "\r\n" );
        } 
        // put in
        // mail_to => array of mailadresses, or string splittet with ,
        // cc => array of mailadresses, or string splittet with ,
        // cc => array of mailadresses, or string splittet with ,
        function &send( $mail_to, $subject, $message, $cc = "", $bcc = "" )
        { 
            // Fix any bare linefeeds in the message to make it RFC821 Compliant.
            $message = preg_replace( "/(?<!\r)\n/si", "\r\n", $message ); 
            if ( !trim( $subject ) ) return $this->error = "No email Subject specified";
            if ( !trim( $message ) ) return $this->error = "Email message was blank"; 
            if ( !is_array( $mail_to ) ) $mail_to = explode( ",", $mail_to );
            if ( $cc && !is_array( $cc ) ) $cc = explode( ",", $cc );
            if ( $bcc && !is_array( $bcc ) ) $bcc = explode( ",", $bcc ); 
            if ( !$this->socket = fsockopen( $this->server, 25, $errno, $errstr, 20 ) )
                return $this->error = "Could not connect to smtp host : $errno : $errstr";
            if ( $this->server_parse( "220" ) )
                return $this->error; 
            if ( !$this->put( "EHLO " . $this->server ) )
                return $this->error = "cannot send EHLO Command";
            if ( $this->server_parse( "250" ) )
                return $this->error; 
            if ( !empty( $this->user_name ) && !empty( $this->user_pass ) ) {
                if ( !$this->put( "AUTH LOGIN" ) )
                    return $this->error = "Cannot send AUTH LOGIN Command";
                if ( $this->server_parse( "334" ) )
                    return $this->error;
                if ( !$this->put( base64_encode( $this->user_name ) ) )
                    return $this->error = "Cannot send LOGIN USER";
                if ( $this->server_parse( "334" ) )
                    return $this->error;
                if ( !$this->put( base64_encode( $this->user_pass ) ) )
                    return $this->error = "Cannot send USER PASS";
                if ( $this->server_parse( "235" ) )
                    return $this->error;
            } 
            if ( !$this->put( "MAIL FROM: " . $this->from ) )
                return $this->error = "Cannot send MAIL FROM";
            if ( $this->server_parse( "250" ) )
                return $this->error; 
            $to_header = "FROM: <" . $this->from . "> \r\n";
            $to_header .= "To: ";
            @reset( $mail_to );
            while ( list( , $mail_to_address ) = each( $mail_to ) ) {
                $mail_to_address = trim( $mail_to_address );
                if ( preg_match( '/.+@.+/', $mail_to_address ) ) {
                    fputs( $this->socket, "RCPT TO: $mail_to_address\r\n" );
                    $this->server_parse( "250" );
                } 
                $to_header .= "$mail_to_address, ";
            } 
            if ( !empty( $bcc ) ) {
                @reset( $bcc );
                while ( list( , $bcc_address ) = each( $bcc ) ) {
                    $bcc_address = trim( $bcc_address );
                    if ( preg_match( '/.+@.+/', $bcc_address ) ) {
                        fputs( $this->socket, "RCPT TO: $bcc_address\r\n" );
                        $this->server_parse( "250" );
                    } 
                } 
            } 
            if ( !empty( $cc ) ) {
                @reset( $cc );
                while ( list( , $cc_address ) = each( $cc ) ) {
                    $cc_address = trim( $cc_address );
                    if ( preg_match( '/.+@.+/', $cc_address ) ) {
                        fputs( $this->socket, "RCPT TO: $cc_address\r\n" );
                        $this->server_parse( "250" );
                    } 
                } 
                $to_header .= "$cc_address, ";
            } 
            fputs( $this->socket, "DATA\r\n" ); 
            $this->server_parse( "354" ); 
            fputs( $this->socket, "Subject: $subject\r\n" ); 
            fputs( $this->socket, "$to_header\r\n" ); 
            fputs( $this->socket, "\r\n\r\n" ); 
            fputs( $this->socket, "$message\r\n" ); 
            fputs( $this->socket, ".\r\n" );
            $this->server_parse( "250" ); 
            fputs( $this->socket, "QUIT\r\n" );
            fclose( $this->socket );
            $this->socket = null;
        } 
    } 
} 

LG
Clemens
 
          
 
							
						 
							
						 
							
						

Kommentar