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.

Email Forwarder Script

Discussion in 'cPanel Developers' started by kabatak, Aug 24, 2011.

  1. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    80
    Likes Received:
    1
    Trophy Points:
    8
    Hello,

    I need to create several email forwarders and I want to automate it.

    I found a PHP script somewhere which no longer works so I tried to modify but I couldn't get it work.

    PHP:
    $cpuser 'user';
    $cppass 'pass';
    $cpdomain 'example.com';
    $cpskin 'x3';
    $url "http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddfwd.html";

    $a['email'] = 'test';
    $a['domain'] = $cpdomain;
    $a['fwdopt'] = 'fwd';
    $a['fwdemail'] = 'test@example.com';


    $c curl_init();
    curl_setopt($cCURLOPT_URL$url);
    curl_setopt($cCURLOPT_POSTtrue);
    curl_setopt($cCURLOPT_POSTFIELDShttp_build_query($a));
    curl_setopt($cCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($cCURLOPT_RETURNTRANSFERtrue);
    var_dump(curl_exec ($c));
    curl_close ($c);
    Can anybody guide me or point me to right direction? Basically I just need to automate the email forwarder creation (using PHP if possible). Thanks
     
  2. kabatak

    kabatak Well-Known Member

    Joined:
    Jun 10, 2009
    Messages:
    80
    Likes Received:
    1
    Trophy Points:
    8
    I actually figured it out, to those interested here's how:

    1. Download the cPanel XMLAPI Client Class at https://github.com/CpanelInc/xmlapi-php

    2. Edit and use this code:

    PHP:
    include_once "xmlapi.php" ;

    $ip 'your host IP or domain';
    $root_pass 'example pass';

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("your root username"$root_pass);

    $xmlapi->set_debug(1);


    // refer to this http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiEmail#Email::addforward for the values of:
    $p['domain']    = 'example.com';
    $p['email']        = 'test'
    $p['fwdopt']    = 'fwd';
    $p['fwdemail']    = 'info@example.com';

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

    var_dump($res);

     
  3. Naresh Kumar

    Naresh Kumar Registered

    Joined:
    Sep 5, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Reseller Owner
    Hi,

    I have made the required changes but while executing the file I am getting some error

    "Warning: file_get_contents() [function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in C:\wamp\www\test\cpanel email account\xmlapi.php on line 752"

    Please help what should I do if I am not having the https in my domain
     
Loading...

Share This Page