malin Posted December 25, 2019 Share Posted December 25, 2019 <?php /** * Created by PhpStorm. * User: ldl * Date: 2019/12/25 * Time: 10:24 PM */ try { $mergefields = array( 'client_id' => 3, 'service_id' => 330, 'service_product' => 'This is a product', 'service_domain' => 'sampledomain.com' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, '../../includes/api.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array( 'action' => 'SendAdminEmail', // See https://developers.whmcs.com/api/authentication 'username' => 'admin123', 'password' => 'adminpwd', 'messagename' => 'Dedicated/VPS Server Welcome Email', 'mergefields' => $mergefields,//array('client_id' => 1, 'service_id' => 1, 'service_product' => 'This is a product', 'service_domain' => 'sampledomain.com'), 'responsetype' => $responsetype, ) ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); echo $response; }catch (Exception $e) { echo $e; return; } echo '200'; return; You see my upper code in a `path-to-whmcs/admin/test05.php`, I follow the [API document](https://developers.whmcs.com/api-reference/sendadminemail/ But it send email fail, there even echo `200`, but the `$response` is blank. there only echo `200`. Who can tell me why there is issue in sendAdminEmail? 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Marcus Posted December 25, 2019 Share Posted December 25, 2019 You are only attempting to catch an Exception, WHMCS does not throw an exception if the API command fails. You need to interpret the response and throw your own Exception if needed in this case. The way your code is structure, it would only hit the catch if cURL throws an exception. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.