title: Create emails accounts using PHP
body: <p>I am in the process of trying to create emails using PHP.</p>
  
  <p>This is my code so far it is very basic until I can get a working script. This is the closest I have got but it says it has added the email although in cpanel the email doesn't exist so it obviously isn't :)</p>
  
  <p>Please note the following information within this code has been edited for security reasons (e.g. not a real password, username or domain).</p>
  
  <p>This is the code I found and have been trying to work out..</p>
  
  <pre><code>&lt;?php
  
  // cPanel info
  $cpuser = 'someusername'; // cPanel username
  $cppass = 'somepassword'; // cPanel password
  $cpdomain = 'somesite.com'; // cPanel domain or IP
  $cpskin = 'someskin';  // cPanel skin. Mostly x or x2. 
  // See following URL to know how to determine your cPanel skin
  // http://www.zubrag.com/articles/determine-cpanel-skin.php
  
  // Default email info for new email accounts
  // These will only be used if not passed via URL
  $epass = 'hispassword'; // email password
  $edomain = 'somesite.com'; // email domain (usually same as cPanel domain above)
  $equota = 20; // amount of space in megabytes
  
  
  function getVar($name, $def = '') {
    if (isset($_REQUEST[$name]))
      return $_REQUEST[$name];
    else 
      return $def;
  }
  
  // check if overrides passed
  $euser = getVar('user', '');
  $epass = getVar('pass', $epass);
  $edomain = getVar('domain', $edomain);
  $equota = getVar('quota', $equota);
  
  $msg = 'check';
  
  if (!empty($euser))
  while(true) {
  
    // Create email account
    $f = fopen ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&amp;domain=$edomain&amp;password=$epass&amp;quota=$equota", "r");
    if (!$f) {
      $msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';
      break;
    }
  
    $msg = "&lt;h2&gt;Email account {$euser}@{$edomain} created.&lt;/h2&gt;";
  
    // Check result
    while (!feof ($f)) {
      $line = fgets ($f, 1024);
      if (ereg ("already exists", $line, $out)) {
        $msg = "&lt;h2&gt;Email account {$euser}@{$edomain} already exists.&lt;/h2&gt;";
        break;
      }
    }
    @fclose($f);
  
    break;
  
  }
  
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;&lt;title&gt;cPanel Email Account Creator&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;?php echo '&lt;div style="color:red"&gt;'.$msg.'&lt;/div&gt;'; ?&gt;
  &lt;h1&gt;cPanel Email Account Creator&lt;/h1&gt;
  &lt;form name="frmEmail" method="post"&gt;
  &lt;table width="400" border="0"&gt;
  &lt;tr&gt;&lt;td&gt;Username:&lt;/td&gt;&lt;td&gt;&lt;input name="user" size="20" value="&lt;?php echo htmlentities($euser); ?&gt;" /&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Password:&lt;/td&gt;&lt;td&gt;&lt;input name="pass" size="20" type="password" /&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan="2" align="center"&gt;&lt;hr /&gt;&lt;input name="submit" type="submit" value="Create Email Account" /&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thank you in advance :)</p>
  
  <p>Andrew </p>