The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

API to create/delete forwarder and aliases

Discussion in 'cPanel Developers' started by ppetree, May 30, 2012.

  1. ppetree

    ppetree Registered

    Joined:
    May 30, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi!

    cpanel: 11.32.2 (build 25)
    exim: 4.77

    Ideally, I need to use PHP to programatically create aliases for a forwarded email address.

    What I have is dothis@domain.com piped to a php script... this works fine and now I want to create aliases for that email address programatically.

    Baring that, I want to create multiple forwarders for that same pipe to php script.

    I've downloaded both xml-php class and cpanel-public-phpapi class off of github and read through that, read the online docs and I see no mention anywhere of creating aliases or forwarders.

    Any help would be greatly appreciated!

    Thanks!

    Pete
     
    #1 ppetree, May 30, 2012
    Last edited: May 30, 2012
  2. charsleysa

    charsleysa Active Member

    Joined:
    Jul 18, 2011
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Palmerston North, New Zealand
    cPanel Access Level:
    Root Administrator
  3. philipnewmannz

    philipnewmannz Registered

    Joined:
    Jun 3, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hi Pete,

    I came up with this solution to add a forwarder using the cPanel API that is piped to a script.

    Code:
    <?php
    include_once "../includes/class/XmlApi_cPanel.php" ; 
    $host 		= 'yourhost.com'; 
    $user 		= 'username';
    $password	= 'password'; 
    
    $xmlapi = new xmlapi($host, $user, $password); 
    $xmlapi->password_auth("username", "password"); 
    
    $xmlapi->set_port(2083);
    
    $xmlapi->set_debug(1); 
    
    
    $p['domain']    = 'yourhost.com'; 
    $p['email']     = 'beer';  
    $p['fwdopt']    = 'pipe'; 
    $p['pipefwd']   = '/home/'.$user.'/public_html/parsingScript.php'; 
    #$p['forwarder']	 = 'beer@yourhost.com=|/home/yourhost/public_html/parsingScript.php';
    
    $res = $xmlapi->api2_query($user, 'Email', 'addforward', $p); 
    #$res = $xmlapi->api1_query($user, 'Email', 'delforward', $p); 
    var_dump($res);  
    ?>
    The problem I have been having is the 'delforward' works nicely if you are deleting another email address but I haven't worked out how to delete items that work with the pipe method... You will note the port has been changed to the cPanal API as it defaults to the WHM one as I don't have access to a WHM as I'm not a reseller.

    That's my two cents anyway.

    Hope it's helpful
     
    #3 philipnewmannz, Jun 3, 2012
    Last edited: Jun 3, 2012
Loading...

Share This Page