PHP Script generating forwarders programmatically

organic

Member
Apr 26, 2009
8
0
51
Hi there,

I'd like to programmatically add forwarder email addresses to a specific domain. I have an application that needs to give users a custom email address, and I'd like to append that address to the /etc/valiases/domain.com file.

I have full root/reseller/everything access to the machine, and I'm wondering what's the best way to do this? I'd prefer not to use suPHP.

What else can I do?

Thanks, Organic.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
13
313
Houston, TX
cPanel Access Level
Root Administrator
Hi there,

I'd like to programmatically add forwarder email addresses to a specific domain. I have an application that needs to give users a custom email address, and I'd like to append that address to the /etc/valiases/domain.com file.

I have full root/reseller/everything access to the machine, and I'm wondering what's the best way to do this? I'd prefer not to use suPHP.

What else can I do?

Thanks, Organic.
You could call the API2 function for adding an email forwarder via our XML API.

Code:
<?cp Email::addforward(email=EMAIL,domain=DOMAIN,fwdopt=FWDOPT,failmsgs=FAILMSGS,pipefwd=PIPEFWD,fwdemail=FWDEMAIL ?>
Where:

EMAIL = the portion of the email address (to be forwarded) before @. This parameter should never contain the @ symbol.

DOMAIN = the portion of the email address (to be forwarded) after @. This parameter should never contain the @ symbol

FWDOPT is fwd if forwarding to an email address, fail if you want to display a failure message, pipe if you want to pipe the email to a shell script in that cPanel account.

FAILMSGS is used if you selected to display a delivery failure message. This is the failure message that will be sent to the sender of the email.

PIPEFWD is used if you select to pipe to a shell script. This is a path to the shell script on the cPanel account that owns this email address.

FWDEMAIL is used if you select to forward to another email address. This is the full email address messages should be forwarded to.

For documentation on calling this from the XML API, visit: http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CallingAPIFunctions

If you prefer to use a pre-assembled PHP 5 class, check out Matt's code at: http://forums.cpanel.net/showthread.php?t=111897