Hallo,
ichhabe hier mal ein Script gefunden, welches Mails direkt per Socket an den Mailserver schickt. Nun wollte ich es endlich mal einbauen und zum Laufen bringen, jedoch bekomme ich Fehlermeldungen und weis nicht mehr weiter. Ich habe auch noch keine großen Erfahrungen mit Socket-Funktionen.
Hier mal das Script:
Meine erste Frage: Was gebe ich als Mailserver an? z.B. mail.meinserver.de oder muß da noch was vor, wie z.B. smtp://mail.meinserver.de?
Ich bekomme folgende Fehlermeldung:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /srv/www/htdocs/web2/html/test/smtp_mailer.php4 on line 70
Warning: fsockopen() [function.fsockopen]: unable to connect to :25 in /srv/www/htdocs/web2/html/test/smtp_mailer.php4 on line 70
Could not connect to smtp host : 25 : Inappropriate ioctl for device
Kann mir da jemand weiter helfen das Dink zum Laufen zu bringen?
Danke,
Andi
ichhabe hier mal ein Script gefunden, welches Mails direkt per Socket an den Mailserver schickt. Nun wollte ich es endlich mal einbauen und zum Laufen bringen, jedoch bekomme ich Fehlermeldungen und weis nicht mehr weiter. Ich habe auch noch keine großen Erfahrungen mit Socket-Funktionen.
Hier mal das Script:
PHP-Code:
if ( !isset( $_CLASS_SMTP_ ) ) {
$_CLASS_SMTP_ = 1;
class SMTP {
var $server = "mein.mailserver.de";
var $user_name = "username";
var $user_pass = "passwort";
var $from = "test@postfach.de";
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;
}
}
}
#----------------- Hier rufe ich die Klasse auf -----------------
$recipients[] = "test1@empfaenger.de";
$recipients[] = "test2@empfaenger.de";
$recipients[] = "test3@empfaenger.de";
$smtp = new SMTP( $server, $user_name, $user_pass );
$error = $smtp->send( array( $recipients ), "Testmail", "Dies ist ein Test" );
if($error)echo$error;
Ich bekomme folgende Fehlermeldung:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /srv/www/htdocs/web2/html/test/smtp_mailer.php4 on line 70
Warning: fsockopen() [function.fsockopen]: unable to connect to :25 in /srv/www/htdocs/web2/html/test/smtp_mailer.php4 on line 70
Could not connect to smtp host : 25 : Inappropriate ioctl for device
Kann mir da jemand weiter helfen das Dink zum Laufen zu bringen?
Danke,
Andi
Kommentar