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.

Programatically creating e-mail forwarders

Discussion in 'cPanel Developers' started by MajSeph, May 9, 2012.

  1. MajSeph

    MajSeph Registered

    Joined:
    May 4, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    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:
    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. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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. MajSeph

    MajSeph Registered

    Joined:
    May 4, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    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. letens

    letens Registered

    Joined:
    Apr 13, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    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???
     
  5. letens

    letens Registered

    Joined:
    Apr 13, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    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 ...
     
Loading...

Share This Page