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.

Create / Delete Forwarders Piped to File.

Discussion in 'cPanel Developers' started by philipnewmannz, Jun 4, 2012.

  1. philipnewmannz

    philipnewmannz Registered

    Joined:
    Jun 3, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Here is a little solution I've managed to come up with for 'creating' new forwarders using the API. It is a pretty simple process. I have tested this for me and it works.

    PHP:
    <?php
    // include the class.
    include_once "cPanel.php" 
    // set up the vars
    $host         'yourhost.com'
    $user         'username';
    $password            'password'

    // create the object
    $xmlapi = new xmlapi($host$user$password); 
    // set the port, this is needed as it will default to the whm.
    $xmlapi->set_port(2083);
    // turn debug mode on.
    $xmlapi->set_debug(1); 
    // set up param array.
    $vars['domain']    = 'yourhost.com'
    $vars['email']     = 'beer';  
    $vars['fwdopt']    = 'pipe';
    $vars['pipefwd']   = '/home/'.$user.'/public_html/parsingScript.php'

    $result $xmlapi->api2_query($user'Email''addforward'$vars); 
    print_r($result);  
    ?>
    The above code will add a the forwarder beer@yourdomain.com to send all email to /home/username/public_html/parsingScript.php. This works nicely.

    My problem now begins when I try and delete the forwarder.

    Here is my code:

    PHP:
    <?php
    // include the class.
    include_once "cPanel.php" 
    // set up the vars
    $host         'yourhost.com'
    $user         'username';
    $password            'password'

    // create the object
    $xmlapi = new xmlapi($host$user$password); 
    // set the port, this is needed as it will default to the whm.
    $xmlapi->set_port(2083);
    // turn debug mode on.
    $xmlapi->set_debug(1); 
    // set up param array.
    $vars['forwarder']   = 'beer@yourhost.com=|/home/username/public_html/parsingScript.php'

    $result $xmlapi->api1_query($user'Email''delforward'$vars); 
    print_r($result);  
    ?>
    This code sends out the result as:

    SimpleXMLElement Object ( [module] => Email [func] => delforward [type] => event [source] => internal [apiversion] => 1 [data] => SimpleXMLElement Object ( [result] => SimpleXMLElement Object ( ) ) [event] => SimpleXMLElement Object ( [result] => 1 ) [postevent] => SimpleXMLElement Object ( [result] => 1 ) [preevent] => SimpleXMLElement Object ( [result] => 1 ) )

    Can anyone make any suggestions to what I might be doing wrong?
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi philipnewmannz,

    Since you're making an API1 call, you need to use an ordinal array and not an associative array. The order that the arguments are presented in the API1 documentation is the order that you'd use in you code.

    So for API1 Email::delforward, the 'forward' argument should be in index '0':
    PHP:
    $value_to_delete='beer@yourhost.com=|/home/username/public_html/parsingScript.php';
    $vars = array($value_to_delete);     # or $vars[0] = $value_to_delete;

    $result $xmlapi->api1_query($user'Email''delforward'$vars);
    Regards,
    -DavidN
     
Loading...

Share This Page