By default postfix & dovecot get their users from the system. This is /etc/passwd
on a UNIX/Linux box.
Managing this from a PHP script is possible, but not too pretty.
You can use
posix_getpwnam
to check if a username exists, and get information about this user.Adding users is best done with
useradd(8)
on Linux. You will need to useexec()
to launch this shell utility. Example usage might be:$pw = crypt($_POST['password'], '$6$1234567890123456'); # This should be 16 characters of random salt exec(sprintf('useradd --groups mailuser --no-user-group --shell nologin --password %s', escapeshellarg($pw));
I wouldn't really recommend this, though.
What I would recommend, is storing your users in a SQL database, such as PostgreSQL, MySQL, or SQLite. This is fairly easy to set up, and on the PHP side all you have to do is add/remove/update rows on the database. This is probably the best solution since it's not too complex, yet still fairly flexible.
The postfix page has a few "HOWTO's" on the subject, and so does dovecot.
Aa a final option, there's LDAP. LDAP is more complex, but arguably 'better' & more flexible. PHP has a LDAP interface.