PHP code example of thefox / smtpd

1. Go to this page and download the library: Download thefox/smtpd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thefox / smtpd example snippets


$server = new Server(...);

$event = new Event(Event::TRIGGER_NEW_MAIL, null, function(Event $event, $from, $rcpts, $mail){
	// Do stuff: handle email, ...
});
$server->addEvent($event);
$server->loop();

$server = new Server(...);

$event = new Event(Event::TRIGGER_AUTH_ATTEMPT, null, function(Event $event, $type, $credentials): bool{
	// Do stuff: Check credentials against database, ...
	return true;
});
$server->addEvent($event);
$server->loop();

$server = new Server(...);

// Set up server here.
// Add Events, etc, ...

while(myApplicationRuns()){
	// Do stuff your application needs.
	// ...
	
	// Run main SMTPd loop, once.
	$server->run();
	usleep(10000); // Never run a main thread loop without sleep. Never!
}