Results 1 to 5 of 5

Thread: Programatically creating e-mail forwarders

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    4
    cPanel/WHM Access Level

    Website Owner

    Exclamation Programatically creating e-mail forwarders

    I tried posting this under the E-Mail discussion forum but have not even had one reply, not even if it was the appropriate forum. So I will try posting this again in here this time.

    This will be a fairly big post, I will try explaining what I am trying to accomplish and the hurdles I've been having.

    Goal: To be able to create en e-mail forwarder through PHP

    Problem: I do not have root access, the hosting company does, they just happen to have cPanel.

    What I've tried:

    I've been going through various resources on the forums here, trying them one at a time and seeing what works.

    - The first thing I tried was: http://forums.cpanel.net/f42/php-scr...ly-115569.html

    But without root access I could not put it where it was needed.

    - Then I read through: http://forums.cpanel.net/f42/xmlapi-...ss-111897.html

    Tried implementing it with:

    PHP Code:
    include_once "xmlapi.php" ;
    $ip 'mysite.ca';
    $root_pass 'accountPassword';

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("accountUsername"$root_pass);

    $xmlapi->set_debug(1);


    $p['domain']    = 'mysite.ca';
    $p['email']        = 'testUser@mysite.ca'
    $p['fwdopt']    = 'pipe';
    $p['pipefwd']    = '/home/accountUsername/public_html/parsingScript.php';

    $res $xmlapi->api2_query('accountUsername''Email''addforward'$p);

    var_dump($res); 
    I replaced the variables and values for the purpose of the explanation, such as accountUsername, accountPassword, mysite.ca and parsingScript.php

    Which failed drastically, for what I'm assuming is the lack of root administration password.

    -----

    This site is being done under a shared hosting domain, so I don't imagine getting root access in the near future. What are my options? When I asked this question to the hosting providers they seemed to believe I needed a better php coder ...

    What can I do in order to have forwarders created automatically that will not require root access on my part?

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,307
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Programatically creating e-mail forwarders

    Okay, so some good news: you can use the API to do this with just cPanel access.

    Instead of providing root login credentials, you will use your cPanel account's username and password. However, and this is important, you must tell the API to login to port 2082 or port 2083. Otherwise, it will try to log into WHM, which you have no access to, and it will fail. You'll see examples of setting the port in the example files (usually they set it to 2086 which is a WHM port).

    Also, $p['email'] should be the part of the email address before the @ sign, not the entire email address. I realize this is counter-intuitive. If you just think of it as if you were filling out the forwarder form in cPanel, it'll make more sense and be easier to remember .

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    4
    cPanel/WHM Access Level

    Website Owner

    Default Re: Programatically creating e-mail forwarders

    You, my friend, are amazing.

    That is exactly what I needed. The reason I had: $p['email'] = 'testUser@mysite.ca'; was to try out something different and see if it worked instead, but when it did not I was disappointed.

    Your method worked perfectly.

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    2
    cPanel/WHM Access Level

    Website Owner

    Default Re: Programatically creating e-mail forwarders

    Hi,
    I'm having this problem also, my site is hosted on justhost.com and I keep on getting this error:
    object(SimpleXMLElement)#2 (2) { ["error"]=> string(13) "Access denied" ["data"]=> object(SimpleXMLElement)#3 (2) { ["result"]=> string(1) "0" ["reason"]=> string(13) "Access denied" } }

    My php file is:
    <?php
    include_once "xmlapi.php";

    $ip = 'myDomain.com';
    $root_pass = 'myPassword';

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("myAccountname", $root_pass);

    $xmlapi->set_debug(1);


    $p['domain'] = 'myDomain.com';
    $p['email'] = 'testaccount';
    $p['fwdopt'] = 'pipe';
    $p['pipefwd'] = '/home/myAccountname/public_html/parsingScript.php';

    $res = $xmlapi->api2_query('picsawall.com', 'Email', 'addforward', $p);

    var_dump($res);

    ?>
    Can anybody please help???

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    2
    cPanel/WHM Access Level

    Website Owner

    Default Re: Programatically creating e-mail forwarders

    Quote Originally Posted by letens View Post
    Hi,
    I'm having this problem also, my site is hosted on justhost.com and I keep on getting this error:
    object(SimpleXMLElement)#2 (2) { ["error"]=> string(13) "Access denied" ["data"]=> object(SimpleXMLElement)#3 (2) { ["result"]=> string(1) "0" ["reason"]=> string(13) "Access denied" } }

    My php file is:

    Can anybody please help???
    I've also tried in changing the port to 2083 ($xmlapi->set_port(2083) , this gives me no error message anymore but does actually nothing ...

Similar Threads

  1. Programatically creating e-mail forwarders
    By MajSeph in forum E-mail Discussions
    Replies: 1
    Last Post: 05-08-2012, 01:51 PM
  2. E-mail Forwarders
    By vixon in forum Themes and Branding
    Replies: 1
    Last Post: 12-30-2009, 08:28 PM
  3. Creating email forwarders via url.
    By Krrose27 in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 07-10-2007, 11:50 AM
  4. Replies: 1
    Last Post: 11-22-2006, 10:38 AM
  5. programatically generate subdomains
    By robertDouglass in forum cPanel & WHM Discussions
    Replies: 0
    Last Post: 06-06-2004, 05:38 AM