Reputation: 902
I've looked everywhere and most of the responses are about verifying a user's account with an email address. I already have that. I have a whole login/register/account system and news feed and friend system, messages, etc.
What I want, however, is a way to give users the ability to register for an email account.
Let's say They go to example.com to register an account, and once they register, they're given an email which is [email protected], and they can view their inbox/outbox folder, and send mail to anywhere instead of just messaging others on the site. I have a few domains I'd like to do this for.
I don't have a dedicated server, or root access, but I have cPanel and access to do pretty much anything related to my web services. Unlimited emails/ability to use external clients, domains, subdomains, bandwidth, storage, etc. So I don't think there'll be any restrictions on specific stuff I have to set up.
How can I use PHP to register an email, along with access the inbox/outbox?
I'd like to create this myself so I can implement it with my own website, so I'd like to refrain from using RoundCube or some other similar webmail service.
Upvotes: 1
Views: 787
Reputation: 2622
Its 100% possible to create email account programmatically please find the code below from one of my working live project
include("xmlapi.php"); //XMLAPI cpanel client class
// Default whm/cpanel account info
$ip = ""; // should be server IP address or 127.0.0.1 if local server
$account = "";// cpanel user account name
$passwd = '';// cpanel user password
$port =2083;// cpanel secure authentication port unsecure port# 2082
$email_domain = "";// email domain (usually same as cPanel domain)
$email_quota = 50; // default amount of space in megabytes
/*************End of Setting***********************/
$xmlapi = new xmlapi($ip);
$xmlapi->set_port($port); //set port number. cpanel client class allow you to access WHM as well using WHM port.
$xmlapi->password_auth($account, $passwd); // authorization with password. not as secure as hash.
// cpanel email addpop function Parameters
$call = array(domain=>$email_domain, email=>$email_user, password=>$email_pass, quota=>$email_quota);
//$xmlapi->set_debug(1);//output to error file set to 1 to see error_log.
// making call to cpanel api
$result = $xmlapi->api2_query($account, "Email", "addpop", $call );
// cpanel email fwdopt function Parameters
$dest_email="";// if specified by user in the form
$call_f = array(domain=>$email_domain, email=>$email_user, fwdopt=>"fwd", fwdemail=>$dest_email);
$result_forward = $xmlapi->api2_query($account, "Email", "addforward", $call_f); //create a forward if you want
if ($result->data->result == 1){
$msg = $email_user.'@'.$email_domain.' account created';
Here is the class file xmlapi.php
Upvotes: 1