Ankündigung

Einklappen
Keine Ankündigung bisher.

Fehler beim Senden von Mails

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Fehler beim Senden von Mails

    Hallo Zusammen

    Ich habe ein Formular geschrieben, wessen Inhalt ich mir zumaile (Tabelle im Html-Format), funktioniert wunderbar.

    Das Problem ist, dass gewisse Teile, bsp "<td>" durch "<t d>" ersetz wird oder es werden irgendwelche Aufrufezeichen gesetzt.

    Wenn der Inhalt immer gleich ist, treten immer die gleichen Fehler an der selben Stelle auf, wenn ich was anderes eingebe, habe ich auch diese Fehler, aber an einer anderen Stelle, wobei die Stelle nicht mit den editieren Feldern zu tun hat.

    Die Ausgabe, bei mir $message, ist vor der Mailfunktion korrekt!

    An was könnte das liegen.

    Besten Dank für eure Hilfe

    Gruss
    Gomsoo

  • #2
    Hallo gomsoo,
    welche Funktion verwendest du zum Senden der Email? Außerdem wäre es interessant zu wissen, in welchem Format du sie sendest (z. B. Multipart).

    Zur weiteren Analyse könntest du mal folgenden Text ausprobieren:
    012345678901234567890(u. s. w.)
    Möglicherweise werden die Leerzeichen immer nach einer bestimmten Anzahl von Buchstaben eingefügt.

    Gruß
    Michael

    Kommentar


    • #3
      Hallo Michael

      Besten Dank für die Antwort

      Meine Mailfunktion: mail($empfaengerString, $subject, $message, $headers);

      Das es mit den Anzahl Zeichen zu tun hat, kann ich mir schlecht vorstellen, denn wenn ich in meinem Formular ein Zeichen hinzufüge, sind die Auswirkung nicht um ein Zeichen verschoben, sondern sonst irgendwo, kann auch vorher sein!

      Kommentar


      • #4
        Hallo!
        Es wäre vielleicht hilfreich das ganze Script zu sehen, um etwas über deine Fehler sagen zu können. Ich habe mich allerdings vor längerer Zeit auch mal mit dem Simple Mail Transfere Protocol (RFC 821 oder RFC 2821) beschäftigt, da mir die PHP eigene [man]mail()[/man]-Funktion sehr zu Lasten gefallen ist. Dabei ist eine kleine SMTP-Klasse entstanden (Code unten). Mit dieser Klasse kann man relativ einfach und sicher Mails versenden ohne den Stress mit mail() zu haben. Ein Beispiel für den Aufruf der Klasse ist am Ende des Codes zu finden. Da ich leider momentan nicht zuhause bin kann ich leide nicht sagen, ob dies die aktuellste Version ist, sollte sie aber sein.
        MfG, Andy

        PHP-Code:
         <?php  
        error_reporting
        (E_ALL);

        /***
        * Class SmtpConnect

        * The SmtpConnect class enables sending mails via SMTP.
        * It is not very easily operated, but that is not required,
        * because this class should just be the base for an comfortable
        * Mail class. On the basis of some comments to this class i want
        * to add that it sure supports Secure Sockets Layer connections.
        * You just have to modify the host and port in the constructor.

        * @package Mail
        * @subpackage SmtpConnect
        * @version 0.4
        * @author Andreas Wilhelm <Andreas2209@web.de>
        * @copyright Andreas Wilhelm 
        **/  
        class SmtpConnect
        {
            
        // declare class variables
            
        private $host
            private 
        $port;
            
            private 
        $sock;    
            
            private 
        $auth;
            private 
        $authTypes = array(
                
        'LOGIN',
                
        'PLAIN');
            
            private 
        $response;
            private 
        $log;

            
        /**
            * Constructor - Is called when the class is instanced
            *
            * @access: public
            * @param Str $host
            * @param Int $port
            * @return NONE
            */
            
        public function __construct($host='localhost'$port=25)
            {
                
        // set server-variables
                
        $this->host $host;
                
        $this->port $port;
            }

            
        /**
            * connect() - Connects to the given server
            *
            * @access: public
            * @return Boolean
            */
            
        public function connect()
            {        
                
        // control-connection handle is saved to $handle
                
        $this->sock = @fsockopen($this->host$this->port);
                if ( !
        $this->sock OR !$this->check('220') )
                    throw new 
        Exception("Connection failed."); 
                
                
        // switch to non-blocking mode - just return data no response
                
        set_socket_blocking($this->socktrue);
                
                
        // set timeout of the server connection
                
        stream_set_timeout($this->sock0200000);
                
                return 
        true;
            }

            
        /**
            * ehlo() - Sends greeting to secured server
            *
            * @access: public
            * @return Boolean
            */
            
        public function ehlo()
            {
                
        // send EHLO -spezified in RFC 2554
                
        $this->cmd("EHLO " $this->host);
                if( !
        $this->check('250') )
                    throw new 
        Exception("Failed to send EHLO.");
                
                return 
        true;
            }

            
        /**
            * helo() - Sends greeting to server
            *
            * @access: public
            * @return Boolean
            */
            
        public function helo()
            {
                
        // Send the RFC821 specified HELO.
                
        $this->cmd('HELO ' $this->host);    
                if( !
        $this->check('250') )
                    throw new 
        Exception("Failed to send HELO.");
                
                return 
        true;
            }

            
        /**
            * auth() - Sends authentification
            *
            * @access: public
            * @param Str $user
            * @param Str $pwd
            * @param Str $type
            * @return Boolean
            */
            
        public function auth($user$pwd$type)
            {
                if( 
        in_array($type$this->authTypes) )
                {
                    
        // send authentification-identifier
                    
        $this->cmd("AUTH $type");        
                        
                    
        // catch first ready response
                    
        $response $this->getReply();
                    if( 
        substr($response,0,1) != )
                    {
                        throw new 
        Exception("Failed to send AUTH.");
                    }
                }
                
                if( 
        $type == 'LOGIN' )
                {
                    
        // send user-name
                    
        $this->cmd(base64_encode($user));        
                    if( !
        $this->check('334') )
                        throw new 
        Exception("Failed to send user-name.");
                    
                    
        // send password
                    
        $this->cmd(base64_encode($pwd));
                }
                
                elseif( 
        $type == 'PLAIN' )
                {
                    
        // prepare data
                    
        $data base64_encode($user.chr(0).$user.chr(0).$pwd);
                    
        $this->cmd($data);
                }
                
                else
                    throw new 
        Exception("Authentification failed.");
                    
                if( !
        $this->check('235') )
                {
                    throw new 
        Exception("Authentification failed.");
                }
                    
                return 
        true;
            }

            
        /**
            * from() - Sends specified addressor
            *
            * @access: public
            * @param Str $from
            * @return Boolean
            */
            
        public function from($from)
            {
                
        // specify addressor
                
        $this->cmd("MAIL FROM: $from");
                if( !
        $this->check('250') )
                    throw new 
        Exception("Failed to send addressor.");
                
                return 
        true;
            }

            
        /**
            * rcpt() - Sends specified acceptor
            *
            * @access: public
            * @param Str $to
            * @return Boolean
            */
            
        public function rcpt($to)
            {
                
        // send specified acceptor
                
        $this->cmd("RCPT TO: $to");        
                if( !
        $this->check('250') )
                    throw new 
        Exception("Failed to send acceptor.");
                
                return 
        true;
            }
          
            
        /**
            * data() - Sends the data to the server
            *
            * @access: public
            * @param Str $message
            * @param Arr $header
            * @return NONE
            */      
            
        public function data($message$header)
            {
                
        // initiate data-transfere
                
        $this->cmd('DATA'); 
                if( !
        $this->check('354') )
                    throw new 
        Exception("Data-transfere failed.");
                    
                
        // validate header-data
                
        if( !is_array($header) )
                    throw new 
        Exception("Header-data must be an array.");
                    
                
        // initiate counter
                
        $i 0;
                    
                
        // include header data
                
        foreach( $header as $key => $value)
                {
                    
        // send header
                    
        if( $i count($header)-)
                    {
                        
        $this->cmd("$key$value");
                    }
                    
                    else
                    {
                        
        $this->cmd("$key$value\r\n");            
                    }
                    
                    
        $i++;            
                }
            
                
        // send the message
                
        $this->cmd("$message\r\n");
            
                
        // send end parameter
                
        $this->cmd('.');
                
                
        $this->check('250');
            }
          
            
        /**
            * quit() - Closes the server-connection
            *
            * @access: public
            * @return NONE
            */      
            
        public function quit()
            {
                
        $this->cmd("QUIT"); 
                
        $this->check('221');
                
        fclose($this->sock);    
                return 
        true;
            }

            
        /**
            * cmd() - Sets a ftp-command given by the user
            *
            * @access: public
            * @param Str $cmd
            * @return NONE
            */
            
        public function cmd($cmd)
            {
                
        fputs($this->sock"$cmd\r\n");
                
        $this->log("&gt; $cmd");
            }    
            
            
        /**
            * getReply() - Catches the reply of the server
            *
            * @access: public
            * @return String
            */
            
        public function getReply()
            {
                
        $go true;
                
        $message "";
                
                do 
                {    
                    
        $tmp = @fgets($this->sock1024);
                    if(
        $tmp === false
                    {
                        
        $go false;
                    } 
                    
                    else 
                    {
                        
        $message .= $tmp;
                        if( 
        preg_match('/^([0-9]{3})(-(.*[\r\n]{1,2})+\\1)? [^\r\n]+[\r\n]{1,2}$/'$message) ) $go false;
                    }
                } while(
        $go);
                
                
        $this->log($message);
                
                return 
        $message;
            }

            
        /**
            * valid() - Checks if the response of a command is ok
            *
            * @access: public
            * @return Boolean
            */
            
        public function valid()
            {
                
        // get response of the server
                
        $this->response $this->getReply();
                
                
        // check the response and say if everything is allright
                
        return (empty($this->response) || preg_match('/^[5]/'$this->response)) ? false true;
            }
                
            
        /**
            * check() - Checks if the response-code is correct
            *
            * @access: public
            * @param Str $code
            * @return Boolean
            */
            
        public function check($code)
            {
                if( 
        $this->valid() )
                {
                    
        $pat '/^'$code .'/';
                    if( 
        preg_match($pat$this->response))
                    {
                        return 
        true;
                    }                
                }    
                    
                return 
        false;
            }
                    
            
        /**
            * log() - Saves all request to the server and their responses into $this->log
            *
            * @access: private
            * @return NONE
            */
            
        private function log($str)
            {
                
        $this->log .= "$str<br />";
            }
                    
            
        /**
            * getLog() - Prints out all requests to the server and their responses 
            *
            * @access: public
            * @return NONE
            */
            
        public function getLog()
            {
                return 
        $this->log;
            }

        }

        try
        {            
            
        $from 'pseudo@web.net';
            
        $to 'test@web.net';
            
        $date date('r');
            
        $header = array( 
                
        'Date' => $date,
                
        'From' => $from,
                
        'Subject' => 'Sending mail via PHP!',
                
        'To' => $to,
                
        'X-Mailer' => 'Avedo Mailer');
            
        $message "Hello. \nIf you can read this message, I was able to send my first mail with my new SmtpConnect-Class. \nThat's great! So have a beer and enjoy the show! \nMfG, Andy";

            
        $mail = new SmtpConnect('host');
            
        $mail->connect();
            
        $mail->ehlo();
            
        $mail->auth('user''pwd''PLAIN');
            
        $mail->from($from);
            
        $mail->rcpt($to);
            
        $mail->data($message$header);
            
        $mail->quit();
            echo 
        $mail->getLog();
        }

        catch(
        Exception $e
        {
            echo 
        $e->getMessage();
        }
        ?>

        Kommentar

        Lädt...
        X