This is a 'journal entry' describing a simple way (no error checking involved) to dynamically create email accounts using PHP.
**Use this information at your own risk, as it modifies extremely fragile and necessary files.**
I looked through all the WHM, cPanel and exim documentation yesterday, and found absolutely zero about the actual creation of an email address, but found numerous things pointing to the files in the /etc folder. So, I tried manually adding an extra line to the end of each file (shadow, passwd, quota), mimicking the last entry.
I found that if you simply switch out the username in each place, the account automatically appears in the cPanel mail manager. The values for quota and password are encrypted in these files, but a simple copy/paste can put generic values in place.
For example, in quota:
ben:1048576000 (1000Meg Quota)
ben:104857600 (100Megs)
ben:10485760 (10Megs)
erasing the 'ben' entry completely allows an unlimited quota....
The passwd file should look like this, replacing 'ben' with whatever else.
ben:x:759:759::/home/username/mail/yourdomain.com/ben:/bin/bash
I then tried using the php append command to add a new line onto each file, and when plugged into a script that uses variables, this is what you get:
$login = $_POST('login')
$myFile0 = "/home/username/etc/yourdomain.com/quota";
$fh = fopen($myFile0, 'a') or die("can't open file");
$stringData = "$login".":104857600n";
fwrite($fh, $stringData);
fclose($fh);
echo "Email quota set to 100 Megs.
";
(Be sure to add the new line at the end of the file, or else cPanel will get confused and not be able to create any additional accounts)
The password (in the shadow file) is a more difficult encryption than I am familiar with, so if you figure it out, I'd love to know, but it can be circumvented by using a default password, then changing it afterwards.
Keywords: creating dynamic email accounts