Jump to content

Mail Hook not working!


ST4R

Recommended Posts

Hello friends, I have written a hook for WHMCS that saves each email sent to users as a file. However, this hook is not working, and the $vars array is empty and contains no values. Please guide me.

<?php

use WHMCS\User\Client;

function emailSentHook($vars)
{
    $directory = $_SERVER['DOCUMENT_ROOT'] . '/something/';

    $email = $vars['to'];
    $content = $vars['message'];

    file_put_contents($email, $content);
}

add_hook('EmailPreSend', 1, 'emailSentHook');

 

Link to comment
Share on other sites

The $vars array does not contain the keys you are using.
You have the following available:
- $vars['messagename']
- $vars['relid']
- $vars['mergefields']

https://developers.whmcs.com/hooks-reference/everything-else/#EmailPreSend

The EmailPreLog even contains the keys you are trying to access: https://developers.whmcs.com/hooks-reference/everything-else/#EmailPreLog

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated