CPanel Email Address Setup

Want to offer your members a FREE email address, below is a simple code to automatically set up an email address when members confirms email address.

 

Edit /profile_activate.php

 

FIND $update = db_res( "UPDATE `Profiles` SET `Status` = '$status' WHERE `ID` = '$ID';" );

 

AND ABOVE PUT THE FOLLOWING CODE and REMEMBER TO CHANGE THE BLUE TEXT:

 

require_once( BX_DIRECTORY_PATH_INC . 'xmlapi.php' );
                $ip = '127.0.0.1';   //the ip address of your email hosting
                $root_pass = 'ROOTPASSWORD';  //password for cPanel account
                $account = 'CPanelUSERNAME'; //account name for cPanel
                $email_user = $p_arr['NickName'];   //the email account to be created, portion before @
                $email_password = 'DEFAULTPASSWORD';  //the password to be used for the new email account
                $dest_email = $p_arr['Email'];   //the full email account to be forwarded to
                $email_domain = 'DOMAINNAME;  //the email domain (part of email after @)
                $email_quota = '10';  //the mailbox quota for the new account in MB
                $final_email = $p_arr['NickName'].'@YOURDOMAIN.COM';

                // don't change anything from here forward

                $xmlapi = new xmlapi($ip);
                $xmlapi->set_port(2083);
                $xmlapi->password_auth($account,$root_pass);
                $xmlapi->set_output('xml');

                $result = $xmlapi->api1_query($account, 'Email', 'addpop', array($email_user, $email_password, $email_quota, $email_domain) );

                $result_forward = $xmlapi->api2_query($account, 'Email', 'addforward', array(domain => $email_domain, email => $email_user, fwdopt => 'fwd', fwdemail => $dest_email) );
                $update = db_res( "UPDATE `Profiles` SET `Email` = '$final_email' WHERE `ID` = '$ID';" );
                createUserDataFile($p_arr['Email']);
                reparseObjTags('profile', $p_arr['Email']);

 

UPLOAD THE ATTACHED API TO YOUR /INC DIRECTORY

CLEAR THE CACHE

NOTES:

If you don't want to update the email address then create an additional field in PhpMyAdmin in the PROFILE table and use the following code:

 

                $update = db_res( "UPDATE `Profiles` SET `PROFILEFIELD` = '$final_email' WHERE `ID` = '$ID';" );
                createUserDataFile($p_arr['Email']);
                reparseObjTags('profile', $p_arr['Email']);

 

Then you can create a box to display the new email address.

 

 

That's It

xmlapi.php · 85.8K · 337 downloads
Quote · 31 Aug 2015

Thanks for this. This can come in handy for some of our upgradable options. Just curious - is there a way to charge for users getting the email instead of giving one away for free?

caredesign.net
Quote · 1 Sep 2015

Is this totally secure?

ManOfTeal.COM a Proud UNA site, six years running strong!
Quote · 1 Sep 2015

I definitely wouldn't put my root password inside a file in the base directory of my site.

BoonEx Certified Host: Zarconia.net - Fully Supported Shared and Dedicated for Dolphin
Quote · 1 Sep 2015

 

I definitely wouldn't put my root password inside a file in the base directory of my site.

 My thoughts exactly.

ManOfTeal.COM a Proud UNA site, six years running strong!
Quote · 1 Sep 2015

you could put another file in a directory not in your root directory and have it get info from there - just look at the header.inc.php page - it is a perfect example - although I would like to put it in a directory above the root directory, but not sure if that is possible.

caredesign.net
Quote · 1 Sep 2015

 

I definitely wouldn't put my root password inside a file in the base directory of my site.

I wouldn't feel comfortable with this. I think this is an excellent share, though! But I think it would be better to add this to a file outside of /public_html and then load it with an absolute path where it's needed, and to use different credentials than root.

BoonEx Certified Host: Zarconia.net - Fully Supported Shared and Dedicated for Dolphin
Quote · 1 Sep 2015

 

Thanks for this. This can come in handy for some of our upgradable options. Just curious - is there a way to charge for users getting the email instead of giving one away for free?

 I decided to give this for FREE as it would help with branding, I will look at writing a script to offer this as a paid feature.

GEWJ

Quote · 8 Sep 2015

 

you could put another file in a directory not in your root directory and have it get info from there - just look at the header.inc.php page - it is a perfect example - although I would like to put it in a directory above the root directory, but not sure if that is possible.

 You could create the script as a php file and place it outside root directory and used in profile_activate.php the include command to point to the script.

Quote · 8 Sep 2015

 

I definitely wouldn't put my root password inside a file in the base directory of my site.

 Sorry my friend, you need to put the CPanel password and not root.  My bag.

Quote · 8 Sep 2015
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.