php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2008

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 24.12.2008, 09:18  
Neuer Benutzer
 
Registriert seit: 23.10.2008
Beiträge: 4
gomsoo befindet sich auf einem aufstrebenden Ast
Standard 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
gomsoo ist offline  
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 24.12.2008, 10:02  
Neuer Benutzer
 
Registriert seit: 24.12.2008
Beiträge: 1
michael47 befindet sich auf einem aufstrebenden Ast
Standard

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
michael47 ist offline  
Alt 24.12.2008, 10:29  
Neuer Benutzer
 
Registriert seit: 23.10.2008
Beiträge: 4
gomsoo befindet sich auf einem aufstrebenden Ast
Standard

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!
gomsoo ist offline  
Alt 24.12.2008, 12:41  
Erfahrener Benutzer
 
Registriert seit: 06.09.2008
Beiträge: 189
#Avedo befindet sich auf einem aufstrebenden Ast
Standard

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 mail()-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();
}
?>
__________________
I'm so tired of slitting the throats of people calling me a violent psychopath.
#Avedo ist offline  
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Fehler: Unexcepted { Stephan_87 PHP Tipps 2008 6 13.12.2008 21:04
mails von HP an mich senden denjo303 PHP Tipps 2008 7 23.10.2008 16:43
mysql fehler meldung: basicx Datenbanken 1 22.07.2008 09:48
Fehler bei Javascript und Klammernsetzen HTML, Usability und Barrierefreiheit 8 28.07.2005 22:41
unerklärlicher fehler in der registrierungssite matthros PHP Tipps 2005-2 8 12.06.2005 18:08
[Erledigt] Seite wird nicht angezeigt, untersch. Fehler bei IE/FF/Safar PHP-Fortgeschrittene 19 31.05.2005 14:52
Blöder MySQL Fehler PHP Tipps 2005 3 15.05.2005 03:14
E-Mail Funktion läuft ohne Fehler, Mails kommen nicht an PHP Tipps 2005 14 27.04.2005 17:48
Senden von mails mit Anlage aber die Anlage ist corrupt PHP-Fortgeschrittene 5 20.04.2005 12:19
Fehlermeldung - aber kein fehler... Tschuu HTML, Usability und Barrierefreiheit 16 14.03.2005 15:56
Wo liegt der fehler?? PHP-Fortgeschrittene 5 22.12.2004 09:54
von php mails senden test022 PHP Tipps 2004-2 9 21.12.2004 19:56
[Erledigt] mysql fehler PHP Tipps 2004 2 03.11.2004 00:32
array_push nur in begrenzter Anzahl ausführen ? PHP Tipps 2004 2 07.09.2004 09:05
Mails senden PHP-Fortgeschrittene 8 06.06.2004 17:58

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
greeting-fehler, greeting fehler, greeting-fehler., greetingfehler, greeting-fehler fax, \greeting-fehler\, grund: greeting-fehler., avm greeting-fehler, avm greeting fehler, grund: greeting-fehler, 7390 greeting-fehler, fax greeting fehler, 7270 greetings-fehler, 7390 greeting fehler, greeting fehler fax avm, failed to send acceptor was bedeutet, was ist ein greeting-fehler avm, greeting-fehler 7270, greeting fehler faxversand, email greeting fehler

Alle Zeitangaben in WEZ +2. Es ist jetzt 18:15 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum