• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

E-Mail Register shell_exec PHP Script

MailServiceFree

New Pleskian
Dear PP community,

I want to create a free e-mail service.
I'm using a vServer with 200gb (for the first time) on Debian 6 with Parallels Plesk 11 backend.

Now I just want a simple php script which is for guests to register a new mail (for themselves).

I've asked a good programming friend if he could help me, so he did.

He has written a script like this:

Code:
<form method="post" action="">
<input type='hidden' name='submitted' id='submitted' value='1'/>


<label for='email' >Email Address:</label>
<input type='text' name='email' id='email' maxlength="50" />
<br> 
<label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type="submit" name="submit" value="Submit" />


</form>


<?
function sanitize($data) {
$data = strip_tags(trim($data));
$search = array('/[^A-Za-z0-9\. -\!\?\(\)\<\>\@]/');
$data = preg_replace($search, '', $data);
return $data;
}




if(isset($_POST['email'])){
// STRIP OUT ANY UNWANTED STUFF
$_POST['email'] = sanitize($_POST['email']);
$_POST['password'] = sanitize($_POST['password']);




if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$email = $_POST['email'];
} else {
echo "Invalid email<br>";
$_POST['email'] = null;
return;
}


$password = $_POST['password'];




shell_exec ("/usr/local/psa/bin/./mail --create $email -passwd $password -mailbox true");
echo "Your account '$email' has been setup with password '$password'";
}


?>

Looks like it would work, I've tested it, but the shell_exec doesn't work correctly. (index.php permissions are at 755)
I have just this file as index.php I don't need more for the first time, I'll code the other stuff when the index.php works fine.

I've read a bit about Plesk and the creation of mails.
They have written, that shell_exec is disabled in Plesk by default and I have to activate it.

I don't know how and where I can do that.. do you know a solution?

PLEASE ANSWER IF YOU NOW THE SOLUTION...

And no, I won't use XML because I don't know how to work with it.

Thanks in advance!!
 
The shell_exec will not work because it is executed as the webserver user. Obviously that user has no permissions to alter Plesk settings and/or create mailaccounts. Otherwise _everyone_ on a shared server could adjust/change/modify server settings. CLI commands only work as root. You will either need to run sudo, so this is executed as root. But I would recommend using Plesk API/XML as it is much more secure.

shell_exec() is bad practice.
 
Back
Top