Web Hosting Talk







View Full Version : CPanel POP3 mailbox autocreation !!!


hookgr
11-05-2004, 01:28 AM
Hello,
i will be short and clear.

I have a site that provides free email services like yahoo or hotmail does.

I want to make a php script that will automatically add new pop3 mail users on my account!

How this can be done ?

From cpanel they said i can use:
/usr/local/cpanel/cpanel-email
but i tried and can't make it work !!!

Any help guys would be great !!!

EXOWorks
11-05-2004, 09:52 AM
Here is something that I wrote about some months ago:



// **********************************************
// MAIL CREATION
//

$host = "exocrew.com"; // your domain name without the www
$port = 2082;
$path = "/frontend/x/mail/doaddpop.html?domain=exocrew.com&email=$_POST[user]&password=$_POST[pass]&quota=3";

// these lines are changed
$cpaneluser = "USERNAME";
$cpanelpass = "PASSWORD";
$authstr = "$cpaneluser:$cpanelpass";

// Setup the Auth String
$pass = base64_encode($authstr);

$fp = fsockopen($host, $port, $errno, $errstr, $timeout = 30);

if(!$fp)
{
//error tell us
echo "$errstr ($errno)\n";

}
else
{

//send the server request

fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Authorization: Basic $pass \r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");

//loop through the response from the server

while(!feof($fp))
{
fgets($fp, 4096);
}


while(!feof($fp))
{
fgets($fp, 4096);
}

//close fp - we are done with it
fclose($fp);
}

tiamak
11-05-2004, 10:47 AM
Originally posted by Mike_R


$host = "exocrew.com";



or

$host = "ssl://exocrew.com";


if your cpanel needs ssl :)

hookgr
11-05-2004, 01:45 PM
It doesnt work !!!
i tried it again and again,
and tried echoing all variables until i found the problem !!!
the problem is on the path variable !!!

$path = "/frontend/x/mail/doaddpop.html?domain=exocrew.com&email=$_POST[user]&password=$_POST[pass]&quota=3";

when i echo it. everything seems ok, but the quota !!!

i dunno why, but:

[pass]&quota=3"

should return:

password&quota=3"

and it returns:

password"a=3"

So, i found that :
!!!!!!!!!!!!!!!!!!!!!
&quot = "
!!!!!!!!!!!!!!!!!!!!!

can't understand why &quot gets into " !!!!!!!!!
what should i do ???????????????

tiamak
11-05-2004, 03:06 PM
vars should be sent not in path ?? :)

root@goscinnawies:/home/tiacms/familycms# cat includes/email_add.php
<?php
if (auth() && ($_SESSION['USER_LEVEL'] == "99")) {
global $cPanel_login;
global $cPanel_pass;
global $cPanel_address;
global $cPanel_maildomain;
global $cPanel_webmail_url;

global $cPanel_email_add_port;
global $cPanel_email_add_script;
global $cPanel_email_del_script;

if ($_POST[email_login]) {
if ($_POST[email_password] != $_POST[email_password2]) { echo 'you havent retyped your password correctly'; $bad =1;}
if (!eregi("[_\.A-Za-z0-9]",$_POST[email_login])) { echo 'login incorrect: you used invalid characters<br>'; $bad = 1;}
if (!eregi("[_\.A-Za-z0-9]",$_POST[email_password])) {echo 'password incorrect: you used invalid characters<br>'; $bad = 1;}
if (!$bad) {
$zmienne .= "email=".$_POST[email_login]."&";
$zmienne .= "domain=".$cPanel_maildomain."&";
$zmienne .= "password=".$_POST[email_password]."&";
$zmienne .= "quota=".$_POST[quota];

$wynik = http_post($cPanel_address, $cPanel_email_add_port, $cPanel_email_add_script, $zmienne, $cPanel_login, $cPanel_pass);
$wynik = str_replace("\n", "", $wynik);
$wynik = str_replace("\n\n", "", $wynik);
$wynik = str_replace("\n\n\n", "", $wynik);
$wynik = strtolower($wynik);
$wynik = str_replace('sorry', '<font color="red" size="+1">sorry</font>', $wynik);
$wynik = str_replace('failed', '<font color="red" size="+1">failed</font>', $wynik);
$title = 'new email account has been created';
if (strpos($wynik, 'sorry') || strpos($wynik, 'failed')) {
$title = 'oops something went wrong! check server answer for more details...';
} else {
$ea = new db();
$ea->dbq('INSERT INTO emails VALUES ("", "'.$_POST[uid].'", "'.$_POST[email_login].'", "'.$_POST[email_password].'", "'.$cPanel_maildomain.'", "'.$_POST[quota].'")');

}



root@goscinnawies:/home/tiacms/familycms# cat lib/socket_connect.php
<?php
#grabbed from the net with few features for example authentication :)

function http_post($host, $port, $path, $data, $user, $pass)
{
$http_response = "";
$content_length = strlen($data);

$fp = fsockopen($host, $port, $errno, $errstr);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Authorization: Basic ".base64_encode("$user:$pass")."\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while (!feof($fp))
{
$http_response .= fgetss($fp, 128);
}
fclose($fp);
return $http_response;
}
?>

thats from one of my scripts :)
maybe it will give you some more info :)