Page 1 of 1

Sendmail Alias in PHP-scripts

Posted: Thu Mar 09, 2006 3:45 am
by jeex
Sendmail Alias in PHP-scripts
Hello,

I want to make a PHP-script that makes, edits and deletes mail-aliasses on the fly.

My server is Linux with Ensim (using Sendmail). Within Ensim I can of course do these things, but I want a regular PHP-script to manage aliasses.

I have my own Linux + Apache server with root access, but want to solve the problem within my regular PHP scripts.

Thanks

Jeex

Re: Sendmail Alias in PHP-scripts

Posted: Thu Mar 09, 2006 7:35 am
by Chris Corbyn
jeex wrote:Sendmail Alias in PHP-scripts
Hello,

I want to make a PHP-script that makes, edits and deletes mail-aliasses on the fly.

My server is Linux with Ensim (using Sendmail). Within Ensim I can of course do these things, but I want a regular PHP-script to manage aliasses.

I have my own Linux + Apache server with root access, but want to solve the problem within my regular PHP scripts.

Thanks

Jeex
Are you referring to the files under /etc/aliases ?

You'll need to set your permissions on the file to be writable by the web user and that could be dangerous but in any case these are very basic colon separated files so it should be easy with a combination of file(), fopen() and fwrite().

Something like:

Code: Select all

function addAlias($alias, $user)
{
    `echo "$alias : $user" >> /etc/aliases`; //This is easy peasy
}

function delAlias($alias)
{
    $tmp = array();
    $lines = file('/etc/aliases');
    foreach ($lines as $l)
    {
        if (!preg_match('/^'.$alias.' :/', $l)) $tmp[] = $l;
    }
    $data = implode('', $tmp);
    $handle = fopen('/etc/aliases', 'w+');
    fwrite($handle, $data);
    fclose($handle);
}
Obviously, to edit an alias you just delete it and then re-add it.

sendmail

Posted: Thu Mar 09, 2006 7:46 am
by jeex
Thanks a lot,

I was thinking of changing the location defined in sendmail.cf to a location in on of the accessable webdirectories.

If possible with more domains on the same server.

gr

Jeex

Not possible

Posted: Thu Mar 09, 2006 8:37 am
by jeex
If the rights were World-writable, it still wouldn't work because user /root must execute newaliases for every change made.

Maybe virtual hosting is the answer

gr

Jeex

Re: Not possible

Posted: Thu Mar 09, 2006 8:41 am
by Chris Corbyn
jeex wrote:If the rights were World-writable, it still wouldn't work because user /root must execute newaliases for every change made.

Maybe virtual hosting is the answer

gr

Jeex
Maybe exim is the answer ;) You can get it to read from any config files you like... even ones you just made up yourself since it's config files essentially use a programming language of their own. I love it :)

I use exim to serve multiple domains from one server, all with aliases. I have the files secured however but there's no reasn you couldn't make them web writable. No need to reload the server for things like domain additions or alias additions ;)