PHP
Some PHP snippets and applications supporting hosting functions in the CPANEL/WHM environment
AddEmail.PHP using curl
- I have written a sample php script to demonstrate how to create a pop
email box. James Shaver has written a modification to the script which uses
curl.
the script requires some input: in the code below all the xxx's need to be replaced with the appropriate values. Here is the configuration block code
--------------------------------------------------------------------------------
// Domain Logon Details
$username="xxxxx";
$password="xxxxx";// Domain details
$domain="www.xxxxx.com";
$theme="xxxxx";//eg "fantastico_bluelagoon";// Parameters to parse
$eEmail="xxxxx";
$eDomain="xxxxx.com";
$ePassword="xxxxxx";
$eQuota="xx"; // eg"10"; -
The output is a bit raw because I am not knowledgeable with using regular expressions.. still I think you will get the idea. Interestingly the output from the command incorporates some additional comments before the new email name is confirmed eg.
quote:
--------------------------------------------------------------------------------
Account Created
The e-mail account testx@zzzzz.com
with the login<----Doing Null Password Check-->
<----Done Doing Null Password Check-->
<----Doing Null Email Check-->
<----Done Doing Null Email Check-->
<----Doing Max Email Check-->
<----Done Max Email Check-->
<----Grabbing Salt-->
<----Done Grabbing Salt-->
<---crypting()-->
<---done crypting()-->
<---fetch pwnam info-->
<---done fetch pwnam info-->
<---recrecord-->
<---done recrecord-->
<---chown-->
<---done chown-->
<---open PASSWD-->
<---open QUOTA-->
<---open SHADOW-->
<---close QUOTA-->
testx+zzzzzz.com
and password xxxxxx with a quota of 10 megs was successfully created.--------------------------------------------------------------------------------
Download
* For the php file (Right-click and save) http://www.domaj.com/files/addemail.zip
ADDEMAIL.PHP V1.0js
<pre>
<?php
/*
Simple example of creating a pop account using a PHP script
Tony Domigan tony@domaj.com http://www.domaj.com Oct03
Curl Modifications by James Shaver Feb06
*/
// Domain Logon Details
$username="xxxxx";
$password="xxxxx";
// Domain details
$domain="www.xxxxx.com";
$theme="xxxxx";//eg "fantastico_bluelagoon";
// Parameters to parse
$eEmail="xxxxx";
$eDomain="xxxxx.com";
$ePassword="xxxxxx";
$eQuota="xx"; // eg"10";
// Put post fields variable together
$postfields = "email=$eEmail&domain=$eDomain&password=$ePassword"a=$eQuota";
// initialise Curl
$popPost = curl_init();
// Set Curl Option: URL
$url="http://$domain:2082/frontend/$theme/mail/doaddpop.html";
curl_setopt($popPost, CURLOPT_URL, $url);
// Set Curl Option: Username:Password
curl_setopt($popPost, CURLOPT_USERPWD, "$username:$password");
// Set Curl Option: Post style request = true
curl_setopt($popPost, CURLOPT_POST, 1);
// Set Curl Option: Collect result from script
curl_setopt($popPost, CURLOPT_RETURNTRANSFER, 1);
// Set Curl Option: Set timeout to 15 seconds
curl_setopt($popPost, CURLOPT_TIMEOUT, 15);
// Set Curl Option: Post data
curl_setopt($popPost, CURLOPT_POSTFIELDS, $postfields);
// Execute Request, and store result in $tb_post
$popPost_result = curl_exec ($popPost);
// Close Curl
curl_close ($popPost);
//output results
$start = strpos($popPost_result, '<b>Account');
$end = strpos($popPost_result, 'created.');
$subset = substr($popPost_result, $start, $end+8-$start);
$subset = str_replace('login ', "login<br>", $subset); //for neatness
//$subset=str_replace("<!",'<-',$subset); //see the comments
if (preg_match ('/Sorry/i', "$subset")) {
print "<br><b> Sorry that account already exists.</b><br><br>";
//print ($subset);
} elseif(preg_match ('/You must specify/i', "$subset")) {
print "<br><b>You must specify a password.</b><br><br>";
} else {
print ($subset);
print "<br><br>You may now use <b>mail.$domain</b> as your POP3 setting in your mail client or access <b>WebMail</b> by selecting <a href=http://$domain/webmail>Here</a>.
<center>
<br><a href=javascript:history.go(-1)>Go Back</a>
</center>";
}
?>
</pre>
