{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Send Notification","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":"send-notification","__idx":0},"children":["Send Notification"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["send"]}," method is responsible for delivering mail to the mail provider."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In this method, you should craft an appropriately formatted message and transmit it to the messaging service."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The method receives two input arguments:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$params"]}," — An array of configuration parameters for the mail provider."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$message"]}," — The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["WHMCS\\Mail\\Message"]}," object."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"public function send(array $params, Message $message)\n{\n    $host = $params['host'];\n    $username = $params['username'];\n    $password = $params['password'];\n\n    $subject = $message->getSubject();\n    $body = $message->getBody();\n    $plainTextBody = $message->getPlainText();\n\n    $replyTo = '';\n    if ($message->getReplyTo()) {\n        $replyTo = $message->getReplyTo();\n    }\n\n    // Retrieve recipients.\n    foreach ($message->getRecipients('to') as $to) {\n        $recipients['to'] = [\n            'emailAddress' => $to[0],\n            'name' => $to[1],\n        ];\n    }\n    foreach ($message->getRecipients('cc') as $to) {\n        $recipients['cc'] = [\n            'emailAddress' => $to[0],\n            'name' => $to[1],\n        ];\n    }\n    foreach ($message->getRecipients('bcc') as $to) {\n        $recipients['bcc'] = [\n            'emailAddress' => $to[0],\n            'name' => $to[1],\n        ];\n    }\n\n    // Retrieve attachments\n    $attachments = [];\n    foreach ($message->getAttachments() as $attachment) {\n        if (array_key_exists('data', $attachment)) {\n            $attachments[] = [\n                'data' => $attachment['data'],\n                'fileName' => $attachment['filename'],\n            ];\n        } else {\n            $attachments[] = [\n                'filePath' => $attachment['filepath'],\n                'fileName' => $attachment['filename'],\n            ];\n        }\n    }\n\n    // If a filename is provided. Retrieve the attachment\n    // data as required by your Mail Provider.\n\n    // Build API request to remote service\n    $postData = [\n        'username' => $username,\n        'password' => $password,\n        'subject' => $subject,\n        'body-html' => $body,\n        'plaintext-body' => $plainTextbody,\n        'to' => $recipients['to'],\n        'cc' => $recipients['cc'],\n        'bcc' => $recipients['bcc'],\n        'reply-to' => $replyTo,\n        'attachments' => $attachments,\n    ];\n\n    $ch = curl_init();\n    curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/send');\n    curl_setopt($ch, CURLOPT_POST, 1);\n    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n    $response = curl_exec($ch);\n    curl_close($ch);\n\n    if (!$response) {\n        // Throw a human friendly exception on error\n        throw new Exception('No response received from API');\n    }\n}\n"},"children":[]}]},"headings":[{"value":"Send Notification","id":"send-notification","depth":1}],"frontmatter":{"title":"Send Notification","seo":{"title":"Send Notification"}},"lastModified":"2026-08-03T17:00:42.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/mail-providers/send-notification","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}