Home » Web Services » Services_Mailman » Manual
Services_Mailman provides a PHP API to Mailman, the GNU Mailing List Manager. With it, you may suscribe and unsubscribe users to/from a mailing list, enumerate all lists and list a list's members. It utilizes Mailman's web interface via HTTP/HTTPS, so you do not need to interface Python or the mailman binaries.
Getting started
To use Services_Mailman, you need to include it into your PHP file:
<?php
require_once 'Services/Mailman.php';
?>
Then, create a Services_Mailman object and supply the "Admin Links" URL and the admin password:
<?php
$mm = new Services_Mailman('http://example.org/mailman/admin', '', 'adminpass');
?>
If you already know the mailing list you want to work on, specify it as second constructor parameter:
<?php
$mm = new Services_Mailman(
'http://example.org/mailman/admin',
'foo-users',
'adminpass'
);
?>
Error handling
If something goes wrong, Services_Mailman's methods will throw exceptions
of type
Services_Mailman_Exception.
Using it's getMessage() method will give you
a human-readable error message.
Examples
List all available mailing lists on the server
<?php
require_once 'Services/Mailman.php';
$mm = new Services_Mailman('http://example.org', '', 'adminpass');
try {
$mailinglists = $mm->lists();
foreach ($mailinglists as $list) {
echo $list['name'] . "\n";
}
} catch (Services_Mailman_Exception $e) {
die('Error: ' . $e->getMessage());
}
?>
Subscribing a user to a mailing list
<?php
require_once 'Services/Mailman.php';
$mm = new Services_Mailman('http://example.org', 'foo-users', 'adminpass');
try {
$mm->subscribe('user@example.org');
} catch (Services_Mailman_Exception $e) {
die('Error: ' . $e->getMessage());
}
?>
Unsubscribing a user from a mailing list
<?php
require_once 'Services/Mailman.php';
$mm = new Services_Mailman('http://example.org', 'foo-users', 'adminpass');
try {
$mm->unsubscribe('user@example.org');
} catch (Services_Mailman_Exception $e) {
die('Error: ' . $e->getMessage());
}
?>