[Resolved] PHP Script creates email account but fails to create forwarder
Hi.
I have a script I am using to create an email account and forwarder using a POST from an campaign. It is succeeding in creating the email account, but does not create the forwarder. I'd appreciate any help on why that might be. I've scoured the forums, and can't see that the script is non-compliant. Anyway, here it is:
[PHP];
$email_password = $_POST['EmailPassword">;
$dest_email = $_POST['ParentEmail">;
$email_domain = 'domain.com';
$email_quota = '10';
$xmlapi = new xmlapi($ip);
$xmlapi->set_port(2083);
$xmlapi->password_auth($account,$root_pass);
$xmlapi->set_output('xml');
$result = $xmlapi->api1_query($account, 'Email', 'addpop', array($email_user, $email_password, $email_quota, $email_domain) );
$result_forward = $xmlapi->api2_query($account, 'Email', 'addforward', array($email_domain, $email_user, 'fwd', $dest_email) );
?>[/PHP]
-
The API2 call looks syntactically correct. Have you tried 1) Checking the cPanel error logs, or 2) setting $xmlapi->debug to 1 so you can see what the raw API output is? (this is an option provided with the public API you appear to be using) 0 -
[quote="vanessa, post: 1598102">The API2 call looks syntactically correct. Have you tried 1) Checking the cPanel error logs, or 2) setting $xmlapi->debug to 1 so you can see what the raw API output is? (this is an option provided with the public API you appear to be using)
Thanks Vanessa. I don't see anything in the ePanel error logs. And apologies, as I'm not a developer, but how would I set the debug to 1? I tried adding [PHP]$xmlapi->set_debug(1); error_log.[/PHP] But that stopped the script from working at all. I appreciate your taking the time - thank you.0 -
With API2, you're expected to pass an associative array of arguments to the api call. This: [PHP] array($email_domain, $email_user, 'fwd', $dest_email) [/PHP] should be this: [PHP] array('domain' => $email_domain, 'email' => $email_user, 'fwdopt' => 'fwd', 'fwdemail' => $dest_email) [/PHP] 0 -
Dave - awesome - you fixed it! Thank you also Vanessa for your time. Here's the final code in case another rank amateur like me is looking to use the same. [PHP] include 'xmlapi.php' ; $ip = 'nnn.nnn.nnn'; //the ip address of your email hosting $root_pass = 'pppppppp'; //password for cPanel account $account = 'aaaaaaaa'; //account name for cPanel // I'm using $_POST as I'm posting the details for the new account using an http: post from Infusionsoft. // All 3 $_POST parameters need to be changed accordingly if you're using an HTML form. $email_user = $_POST['Username">; //the email account to be created, portion before @ $email_password = $_POST['EmailPassword">; //the password to be used for the new email account $dest_email = $_POST['ParentEmail">; //the full email account to be forwarded to $email_domain = 'domain.com'; //the email domain (part of email after @) $email_quota = '10'; //the mailbox quota for the new account in MB // don't change anything from here forward $xmlapi = new xmlapi($ip); $xmlapi->set_port(2083); $xmlapi->password_auth($account,$root_pass); $xmlapi->set_output('xml'); $result = $xmlapi->api1_query($account, 'Email', 'addpop', array($email_user, $email_password, $email_quota, $email_domain) ); $result_forward = $xmlapi->api2_query($account, 'Email', 'addforward', array(domain => $email_domain, email => $email_user, fwdopt => 'fwd', fwdemail => $dest_email) );[/PHP] For a bit of security, my email account domain is different from my website domain, and is hosted separately. That means that if the file is compromised and someone gets password and username details for this cPanel, "only" my email accounts are compromised, not my website. I'm sure a security guy could make it infinitely more secure, but for my purposes, that's probably enough as the contents of the email accounts are not that important. 0 -
I am happy to see the input you were provided was helpful. I am marking this thread as resolved. 0 -
thanks it will help 0 -
Hi Michael. I just noticed that the first part of the PHP code in my reply is sitting within the body of the message rather than the PHP code itself. Any chance of getting it in there in case anyone wants to copy the code? 0 -
I fixed it for you by moving the code tag up one line. :) 0 -
thank you! 0 -
You're most welcome. :) 0 -
in which directory should i put the script and what should i call it... please help 0 -
in which directory should i put the script and what should i call it... please help
Hello, Could you provide some more details about your purpose for using the script, and how you plan to implement it? Generally there are no restrictions on the name and location. Thanks!0 -
i have found a solution thanks... now i am looking for a script that can allow my clients to make domain redirects in whmcs client area without having to login to cpanel Could you provide some more details about your purpose for using the script, and how you plan to implement it? Generally there are no restrictions on the name and location.
0 -
New i have found a solution thanks... now i am looking for a script that can allow my clients to make domain redirects in whmcs client area without having to login to cpanel
I'm happy to see you were able to find a solution. Feel free to open a new thread on the WHMCS support forums for additional feedback on the WHMCS question: WHMCS Forums Thank you.0
Please sign in to leave a comment.
Comments
14 comments