Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP: Mail versand über SMTP

Empfohlene Antworten

Veröffentlicht

Hi,

wollte wissen ob's ne möglichkeit gibt, mit PHP eMails über nen SMTP Server zu schicken und nicht über mail()??

Hab bedenken ob momentan knapp 4000emails über mail() dem server so gut tun

thx

die mail()-funktion unter php ist auch bei mehr als 4000 mails performant.

alternative:

$fp = fsockopen("mail.server.de", 25);

d.h. direkt an dem smtp-port des mailservers verbinden, HELO, MAIL FROM, RCPT TO und dann noch einen inhalt nach DATA, fertig, ab damit.

s'Amstel

Hi,

wollte wissen ob's ne möglichkeit gibt, mit PHP eMails über nen SMTP Server zu schicken und nicht über mail()??

Hab bedenken ob momentan knapp 4000emails über mail() dem server so gut tun

mail versendet die Mails über den SMTP-Server, der in der PHP.ini eingestellt ist.

Über ini_set könntest du den wohl temporär in deinem Skript ändern.

$fp = fsockopen("mail.server.de", 25);

d.h. direkt an dem smtp-port des mailservers verbinden, HELO, MAIL FROM, RCPT TO und dann noch einen inhalt nach DATA, fertig, ab damit.

das sieht doc hgut aus, bin nur leider nicht der php könner (muss nur im mom)

jetzt die frage bin zwar selber noch auf der suche, aber wie könnte das fertig aussehen?

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;
}
}
}[/PHP]

was haltet ihr davon?

ich habe jetzt noch nicht genau in den Quelltext reingesehen, allerdings fällt mir schnell das alter des Codes auf... (last change: 18.09.2002) ^^

$HTTP_POST_VARS als beispiel wird eigentlich nicht mehr benutzt...ich vermute auf anhieb das da mehr in diese Richtung drin ist und währe daher vorsichtig...nicht alles aus den alten Befehlen funktioniert heute noch genauso....also - meiner Meinung nach - entweder die Klasse überarbeiten oder eine neurere Version suchen.

Da du sagst du bist nicht so PHP könner, gug dich mal auf php.net oder phpforum.de um, die könnten was haben.

welche PHP Version benutzt du ?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.