{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-api/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"SendEmail","description":"Developer documentation for the WHMCS API — the","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"sendemail","__idx":0},"children":["SendEmail"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Send a client Email Notification."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following email templates cannot be sent in this way:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Order Confirmation"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Password Reset Confirmation"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Password Reset Validation"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Quote Accepted"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Quote Accepted Notification"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Quote Delivery with PDF"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Clients Only Bounce Message"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Replies Only Bounce Message"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Affiliate Monthly Referrals Report"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["What you must provide for the Related ID depends upon the type of email being sent."," ","The available options are:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["General Email Type = Client ID (tblclients.id)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Product Email Type = Service ID (tblhosting.id)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Domain Email Type = Domain ID (tbldomains.id)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Invoice Email Type = Invoice ID (tblinvoices.id)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Support Email Type = Ticket ID (tbltickets.id)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Affiliate Email Type = Affiliate ID (tblaffiliates.id)"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Sending Failed"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The generic Sending Failed error response can be caused by one of five possible conditions. They are:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Invalid related ID"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Email template contains no body content after processing (typically a Smarty error)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Welcome email requested for product which has none set"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Hook aborted the sending"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["PHPMailer Sending Error - in this failure condition, an activity log entry will be created recording the error message that occurred"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"request-parameters","__idx":1},"children":["Request Parameters"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Parameter"},"children":["Parameter"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":["Type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Required"},"children":["Required"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["action"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["\"SendEmail\""]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Required"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["messagename"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The name of the client email template to send"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["id"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["int"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The related id for the type of email template. Eg this should be the client id for a general type email"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["customtype"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The type of custom email template to send ('general', 'product', 'domain', 'invoice', 'support', 'affiliate')"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["custommessage"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The HTML message body to send for a custom email"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["customsubject"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The subject to send for a custom email"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["customvars"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["array"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The custom variables to provide to the email template. Can be used for existing and custom emails."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"response-parameters","__idx":2},"children":["Response Parameters"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Parameter"},"children":["Parameter"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":["Type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["result"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["string"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["The result of the operation: success or error"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-request-curl","__idx":3},"children":["Example Request (CURL)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');\ncurl_setopt($ch, CURLOPT_POST, 1);\ncurl_setopt($ch, CURLOPT_POSTFIELDS,\n    http_build_query(\n        array(\n            'action' => 'SendEmail',\n            // See https://developers.whmcs.com/api/authentication\n            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',\n            'password' => 'SECRET_OR_HASHED_PASSWORD',\n            '//example1' => 'example',\n            'messagename' => 'Client Signup Email',\n            'id' => '1',\n            '//example2' => 'example',\n            'customtype' => 'product',\n            'customsubject' => 'Product Welcome Email',\n            'custommessage' => '<p>Thank you for choosing us</p><p>Your custom is appreciated</p><p>{$custommerge}<br />{$custommerge2}</p>',\n            'customvars' => base64_encode(serialize(array(\"custommerge\"=>$populatedvar1, \"custommerge2\"=>$populatedvar2))),\n            'responsetype' => 'json',\n        )\n    )\n);\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n$response = curl_exec($ch);\ncurl_close($ch);\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-request-local-api","__idx":4},"children":["Example Request (Local API)"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"$command = 'SendEmail';\n$postData = array(\n    '//example1' => 'example',\n    'messagename' => 'Client Signup Email',\n    'id' => '1',\n    '//example2' => 'example',\n    'customtype' => 'product',\n    'customsubject' => 'Product Welcome Email',\n    'custommessage' => '<p>Thank you for choosing us</p><p>Your custom is appreciated</p><p>{$custommerge}<br />{$custommerge2}</p>',\n    'customvars' => base64_encode(serialize(array(\"custommerge\"=>$populatedvar1, \"custommerge2\"=>$populatedvar2))),\n);\n$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later\n\n$results = localAPI($command, $postData, $adminUsername);\nprint_r($results);\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example-response-json","__idx":5},"children":["Example Response JSON"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"{\n    \"result\": \"success\"\n}\n"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"error-responses","__idx":6},"children":["Error Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Possible error condition responses include:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["You must provide either an existing email template name or a custom message type"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Invalid message type provided"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A subject is required for a custom message"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A message body is required for a custom message"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The custom variables you provided are invalid."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A related ID is required"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Email Template not found"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Email Template is disabled"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Sending Failed. Please see documentation."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"version-history","__idx":7},"children":["Version History"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Version"},"children":["Version"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Changelog"},"children":["Changelog"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["1.0"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Initial Version"]}]}]}]}]}]},"headings":[{"value":"SendEmail","id":"sendemail","depth":1},{"value":"Request Parameters","id":"request-parameters","depth":3},{"value":"Response Parameters","id":"response-parameters","depth":3},{"value":"Example Request (CURL)","id":"example-request-curl","depth":3},{"value":"Example Request (Local API)","id":"example-request-local-api","depth":3},{"value":"Example Response JSON","id":"example-response-json","depth":3},{"value":"Error Responses","id":"error-responses","depth":3},{"value":"Version History","id":"version-history","depth":3}],"frontmatter":{"title":"SendEmail","seo":{"title":"SendEmail"}},"lastModified":"2026-08-03T17:00:42.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/api-reference/sendemail","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}