V
V
Vahe2015-12-21 19:57:22
PHP
Vahe, 2015-12-21 19:57:22

How to add mail account cPanel, PHP?

How can I add an email account using cPanel and PHP.
such a -php class
using fopen()
cpmail.class.php

<?php
<?php
class cpmail{
  var $cpuser;   
  var $cppass;       
  var $cpdomain;    
  var $cpskin;      

  function cpmail($cpuser,$cppass,$cpdomain,$cpskin='x'){
    $this->cpuser=$cpuser;
  $this->cppass=$cppass;
  $this->cpdomain=$cpdomain;
  $this->cpskin=$cpskin;
  }
  function create($euser,$epass,$equota){
    $path="http://".$this->cpuser.":".$this->cppass."@".$this->cpdomain.":2082/frontend/".$this->cpskin."/mail/doaddpop.html?quota=".$equota."&email=".$euser."&domain=".$this->cpdomain."&password=".$epass;
    $f = fopen($path,"r");
  if (!$f) {
    return('Не удается создать учетную запись электронной почты. Возможные причины: функция "FOPEN" не допускаются на вашем сервере, PHP работает в безопасном режиме');
  }

    while (!feof ($f)) {
    $line = fgets ($f, 1024);
    if (ereg ("уже существует!", $line, $out)) {
      return('Такое учетная запись электронной почты уже существует.');
    }
  }
  fclose($f);
  return "Учетная запись электронной почты создана.";
 }
}

?>

cpmail_example.php
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>cPanel</title>
</head>

<body>

<p><b><font size="5">Cpanel Email Creator</font></b></p>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

  <table border="0" width="52%" style="border-collapse: collapse">
    <tr>
      <td colspan="2">
      <p align="left"><b>Create Email Accounts</b></td>
    </tr>
    <tr>
      <td width="78">
      <p align="right">Username:</td>
      <td><input type="text" name="euser" size="20"></td>
    </tr>
    <tr>
      <td width="78">
      <p align="right">Password:</td>
      <td><input type="password" name="epass" size="20"></td>
    </tr>
    <tr>
      <td width="78">&nbsp;</td>
      <td><input type="submit" value="Create New Account" name="create"></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
<?php
if(isset($_POST['create'])){

 require 'cpmail.class.php';
 $cpanel=new cpmail("rubdnet","secret2001","rubd.net","/frontend/");

 echo $cpanel->create($_POST['euser'],$_POST['epass'],"20");
}
?>
</body>

</html>


Warning: fopen( http://[email protected]:2082/frontend/rvblue/mail/doaddp...

failed to open stream: Connection refused in /home/u562718444/public_html/cpmail.class.php on line 50 Can't create email account Possible reasons: "FOPEN" function is not allowed on your server, PHP is running in secure mode

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-12-22
@vahe_2000

- rewrite the code to use curl instead of fopen
- move to a hosting that allows the use of fopen
- use Google and find a more adequate way. example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question