Results 1 to 2 of 2

Thread: Create / Delete Forwarders Piped to File.

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    2
    cPanel/WHM Access Level

    Website Owner

    Default Create / Delete Forwarders Piped to File.

    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 Code:
    <?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 Code:
    <?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. #2
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default Re: Create / Delete Forwarders Piped to File.

    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 Code:
    $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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Requests

Similar Threads

  1. Dont let me delete forwarders in cpanel
    By camposomar in forum cPanel & WHM Discussions
    Replies: 7
    Last Post: 08-26-2010, 08:09 AM
  2. Cpanel Forwarders Dont Delete
    By whipanor7 in forum cPanel & WHM Discussions
    Replies: 15
    Last Post: 06-21-2010, 07:55 AM
  3. How To Delete ALL Email Forwarders
    By drfb in forum E-mail Discussions
    Replies: 3
    Last Post: 02-10-2009, 02:12 AM
  4. Cant delete email forwarders [moved]
    By ZeNNeC in forum E-mail Discussions
    Replies: 8
    Last Post: 09-20-2005, 02:02 PM
  5. Unable to delete email forwarders
    By meposter in forum cPanel & WHM Discussions
    Replies: 5
    Last Post: 06-03-2004, 10:19 PM