我正在尝试使用PHP创建电子邮件。使用PHP创建电子邮件帐户
这是我的代码到目前为止,它是非常基本的,直到我可以得到一个工作脚本。这是我得到的最接近,但它表示,它已经增加了电子邮件虽然在的cPanel电子邮件不存在,因此它显然没有:)
请注意,该代码中的下列信息已出于安全原因,编辑(例如,不是真实的密码,用户名或域名)。
这是我发现的,并一直在努力制定出代码..
<?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:[email protected]$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass"a=$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>
预先感谢您:)
安德鲁
实际上是什么问题? –
有没有更好的方法来做到这一点,实际工作? - 无需拆开一些开源客户端即可实现此功能。 – Andrew
这是否必须通过cpanel? (可能有帮助:http://stackoverflow.com/questions/6422200/how-to-create-an-email-account-in-cpanel-via-php) – 2013-07-25 23:15:16