Add a Cpanel Email Account
Username
Password
Re-type your Password
© Fiji Web Design™
<?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 '';
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;
}
?>
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
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]
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
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.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
If CPanel uses (forces) https (secure) connections, simply forget the second solution!
I forgot to mention. If cpanel forces https, the method I just posted will most likely not work.
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).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.
I found this great resource: http://www.peej.co.uk/articles/http-auth-with-html-forms.html
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101