使用PHP创建电子邮件帐户 [英] Create emails accounts using PHP

查看:75
本文介绍了使用PHP创建电子邮件帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP创建电子邮件。

I am in the process of trying to create emails using PHP.

到目前为止,这是我的代码,直到获得有效的脚本为止,这是非常基本的。这是我得到的最接近的邮件,但它说它已经添加了电子邮件,尽管在cpanel中该电子邮件不存在,所以它显然不是:)

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 :)

请注意出于安全原因(例如不是真实的密码,用户名或域),已对该代码中的以下信息进行了编辑。

Please note the following information within this code has been edited for security reasons (e.g. not a real password, username or domain).

这是我找到并一直在尝试工作的代码

This is the code I found and have been trying to work out..

<?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&domain=$edomain&password=$epass&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 = "<h2>Email account {$euser}@{$edomain} created.</h2>";

  // Check result
  while (!feof ($f)) {
    $line = fgets ($f, 1024);
    if (ereg ("already exists", $line, $out)) {
      $msg = "<h2>Email account {$euser}@{$edomain} already exists.</h2>";
      break;
    }
  }
  @fclose($f);

  break;

}

?>
<html>
<head><title>cPanel Email Account Creator</title></head>
<body>
<?php echo '<div style="color:red">'.$msg.'</div>'; ?>
<h1>cPanel Email Account Creator</h1>
<form name="frmEmail" method="post">
<table width="400" border="0">
<tr><td>Username:</td><td><input name="user" size="20" value="<?php echo htmlentities($euser); ?>" /></td></tr>
<tr><td>Password:</td><td><input name="pass" size="20" type="password" /></td></tr>
<tr><td colspan="2" align="center"><hr /><input name="submit" type="submit" value="Create Email Account" /></td></tr>
</table>
</form>
</body>
</html>

提前谢谢:)

安德鲁

推荐答案

我认为这就是您要寻找的东西:

I think this is what you're looking for:

$socket = fsockopen($cpdomain,2082);
$cuser = "YourUserName";
$cpassword = "YourPassword";
$authstr = base64_encode("".$cpuser.":".$cppass."");
$in = "GET /frontend/$cpskin/mail/doaddpop.html?email=$euser&$edomain&password=$epass&quota=$equota
HTTP/1.0\r\nAuthorization: Basic $authstr \r\n";
fputs($socket,$in);
fclose( $socket );

这篇关于使用PHP创建电子邮件帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆