| | |
Automatic email creation in cpanel ----PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2004
Posts: 126
Reputation:
Solved Threads: 2
•
•
•
•
Originally Posted by vssp
Hi friends
Is it posssible to create an email account in the cpanel without manualy logging in ? I want to create a php script which logs into the cpanel and create an email account . I hope i would get a solution form u guys
Thanks
you cannot do it, nor cpanel would allow do it even if u create a script.
coz it is a security factor.
•
•
Join Date: May 2005
Posts: 19
Reputation:
Solved Threads: 0
Basically, it's possible, but not easy.
1) You have to do some reverse engineering of CPanel (which normally is forbidden by the licence agreement), to find out how/where CPanel stores the email accounts in its database.
2) You need to do exactly what CPanel does, such as adding the email account to the mailer deamon's user database and (maybe) restart the deamon or rebuild the database, using a console command.
I don't think you'd be able to use the internal CPanel functions from an outside script. Either the code is crypted or you need a valid session to use the functions.
The other way you could do it is as difficult as the first one. You could emulate a browser, open a session and add the email account. But this requires a lot of knowledge about session cookies and the http protocol (how to build the headers).
If CPanel uses (forces) https (secure) connections, simply forget the second solution!
1) You have to do some reverse engineering of CPanel (which normally is forbidden by the licence agreement), to find out how/where CPanel stores the email accounts in its database.
2) You need to do exactly what CPanel does, such as adding the email account to the mailer deamon's user database and (maybe) restart the deamon or rebuild the database, using a console command.
I don't think you'd be able to use the internal CPanel functions from an outside script. Either the code is crypted or you need a valid session to use the functions.
The other way you could do it is as difficult as the first one. You could emulate a browser, open a session and add the email account. But this requires a lot of knowledge about session cookies and the http protocol (how to build the headers).
If CPanel uses (forces) https (secure) connections, simply forget the second solution!
•
•
•
•
Originally Posted by vssp
Hi friends
Is it posssible to create an email account in the cpanel without manualy logging in ? I want to create a php script which logs into the cpanel and create an email account . I hope i would get a solution form u guys
Thanks
Fortunately CPanel does not use sessions, as Rotak mentioned. Therefore constructing the right HTTP request is not difficult.
If you try a http request to the Cpanel url, you will notice that you receive a 401 response header. This is good news since it means Cpanel uses HTTP Basic Authentication (Digest Auth also sends the same header, but since its not supported on all browsers, I guess cpanel opts for Basic Auth). This is easy to make a http request for in php.
With Basic Authentication username and password is passed as plain text . With php you can use the syntax similar to logging into ftp.
http://user:password@domain.com:port
with any of the stream functions, such as fopen, file_get_contents, fsockopen, file etc.
Example:
[PHP]$fp = fopen('http://user:password@domain.com:port', 'r');[/PHP]
For creating an email account on Cpanel, the url is of the structure:
http://[example.com]:[2082]/frontend/[x]/mail/doaddpop.html?email=[test]&domain=[example.com]&password=[test]"a=[10]
The chars in brackets [] are dependant on yoru Cpanel setup or the email account.
Heres an example script:
[PHP]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Add Cpanel Email Accounts</title>
</head>
<body>
<fieldset>
<legend>Add a Cpanel Email Account</legend>
<form name="add_cpemail">
<fieldset>
<legend>Username</legend>
<input type="text" name="username" class="form_text" />
</fieldset>
<fieldset>
<legend>Password</legend>
<input type="password" name="password1" class="form_text" />
</fieldset>
<fieldset>
<legend>Re-type your Password</legend>
<input type="password" name="password2" class="form_text" />
</fieldset>
<fieldset>
<input type="submit" name="send" class="form_button" value="Create Email Account" />
</fieldset>
</form>
</fieldset>
<div style="text-align:center;color:#c0c0c0;">© <a href="http://www.fijiwebdesign.com/">Fiji Web Design</a>™</div>
<script type="text/javascript">
<!--
// form validation
function init() {
var f = document.forms.add_cpemail;
var e = f.elements;
f.onsubmit = function() {
// check username
if (!e.username.value || e.username.value == '') {
alert('Enter a username.');
return false;
}
// check password
if (e.password1.value != e.password2.value) {
alert('Please verify that your password and password confirmation match.');
return false;
}
}
}
window.onload = init();
//-->
</script>
<?php
// required cpanel data
define( 'CPEMAIL_DOMAIN', 'example.com'); // Cpanel domain
define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL
define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL
define( 'CPEMAIL_THEME', 'bluelagoon'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon
define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes
// sensitive cpanel info
define( 'CPEMAIL_USER', 'username'); // Cpanel Username
define( 'CPEMAIL_PASS', 'password'); // Cpanel Password
if (isset($_GET['send'])) {
$username = $_GET['username'];
$password = $_GET['password1'];
$url = 'http'.(CPEMAIL_SSL ? 's' : '').'://'.CPEMAIL_USER.':'.CPEMAIL_PASS.'@'.CPEMAIL_DOMAIN.':'.CPEMAIL_PORT.'/frontend/'.CPEMAIL_THEME.'/mail/doaddpop.html';
$url .= '?email='.$username.'&domain='.CPEMAIL_DOMAIN.'&password='.$password.'"a='.CPEMAIL_QUOTA;
// make the http request to cpanel, this is where the email is created
// this is just like the browser making the request, only php does it for the user
$txt = http_request( $url );
// in a live situation, you would parse the returned html, and see if the email was successfully created.
// because this is dependent on the Cpanel theme, I didnt put it in.
// A simple test example would be:
// if (strpos($txt, 'Successful') !== false) { echo 'Your account was created, please log in.'; }
// the above checks for the occurance of Successful in the returned html, which occurs when an email is created (english)
// note: different Cpanel themes give different html output, and may be in English or other language
echo '<hr />';
echo $txt; // show the result of the http request
}
// makes an fopen request to the url and returns the content
function http_request($url) {
ini_set('user_agent','MSIE 4\.0b2;'); // set user agent as IE browser
$txt = '';
if ($fp = fopen($url, 'r')) {
while( !feof($fp) ) {
$txt .= fread( $fp, 2082 );
}
fclose($fp);
}
return $txt;
}
?>
</body>
</html>
[/PHP]
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Sorry, you need to change the values for the defined vars to match your cpanel setup. You can get these values by logging into cpanel, and creating an email account then, looking at the url.
Heres what you need to change:
[php]
// required cpanel data
define( 'CPEMAIL_DOMAIN', 'example.com'); // Cpanel domain
define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL
define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL
define( 'CPEMAIL_THEME', 'bluelagoon'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon
define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes
// sensitive cpanel info
define( 'CPEMAIL_USER', 'username'); // Cpanel Username
define( 'CPEMAIL_PASS', 'password'); // Cpanel Password
[/php]
Heres what you need to change:
[php]
// required cpanel data
define( 'CPEMAIL_DOMAIN', 'example.com'); // Cpanel domain
define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL
define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL
define( 'CPEMAIL_THEME', 'bluelagoon'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon
define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes
// sensitive cpanel info
define( 'CPEMAIL_USER', 'username'); // Cpanel Username
define( 'CPEMAIL_PASS', 'password'); // Cpanel Password
[/php]
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Another method of logging into sites and doing stuff is to use JavaScript. With xmlHTTPRequest, you can also specify HTTP headers, and thus reply to a Basic Auth header with the username and password.
Problem with this is the same domain policy, but I've seen workaround for this on the web.
But since this is a php forum, I wont post any solutiosn here.
Problem with this is the same domain policy, but I've seen workaround for this on the web.
But since this is a php forum, I wont post any solutiosn here.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
Originally Posted by Rotak
If CPanel uses (forces) https (secure) connections, simply forget the second solution!
You'd have to use some php libs that understand the SSL protocol, like CURL. An alternative is using the Sockets function in PHP, but you'd have to be ready to write a huge lib and know SSL and HTTP well. (I dont think I've seen a SSL lib for php).
•
•
•
•
Originally Posted by digital-ether
Another method of logging into sites and doing stuff is to use JavaScript. With xmlHTTPRequest, you can also specify HTTP headers, and thus reply to a Basic Auth header with the username and password.
Last edited by digital-ether; Aug 2nd, 2006 at 11:42 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Jul 2006
Posts: 197
Reputation:
Solved Threads: 5
Thanks for all i got the solution: refer this link
http://www.zubrag.com/scripts/cpanel...il-account.php
Thsi very usefull for using script to access the cpanel
Thanks
vssp
http://www.zubrag.com/scripts/cpanel...il-account.php
Thsi very usefull for using script to access the cpanel
Thanks
vssp
![]() |
Other Threads in the PHP Forum
- Previous Thread: gif content overflowing error_reporting function seem not suppressing warning
- Next Thread: Remember my password script in php
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alerts apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop overwrite parse paypal pdf php problem query radio random recursion redirect regex remote script search securephp server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube






