Send a mail from my custom module after custom form submit by user I have made a custom form from a custom module. I need to send an email to the admin when user clicks submit. How can I achieve this. Can I use entities here? Say like send mail to [site:mail] or something like that. Also, its pretty odd to see that Rules module does provide an event for this.

Here's my .module file:

&lt;?php

global $user;

function my_module_help($path, $arg) {
  switch ($path) {
    case "admin/help#formtest":
      return '&lt;p&gt;' . t("Test form for accept challenge") . '&lt;/p&gt;';
      break;
  }
}

function my_module_menu() {
  $items = array();
  $items['my_module/form'] = array(
    'title' =&gt; t('My form'),
    'page callback' =&gt; 'my_module_form',
    'access arguments' =&gt; array('access content'),
    'description' =&gt; t('My form'),
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}

function my_module_form() {

 return drupal_get_form('my_module_my_form');

}


function my_module_my_form($form_state) {

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; 'Accept Challenge',
    '#submit' =&gt; array('my_module_action'),
    );

  return $form;
}

function my_module_action($form, &amp;$form_state) {
  drupal_set_message(t('Challenge Accepted'));
  $query = db_insert('challenges')
    -&gt;fields(array(
    'cid' =&gt; '$node-&gt;nid',
    'uid' =&gt; '$user-&gt;uid'
    ))
    -&gt;execute();
}


As you may have noticed there's no text field, well that is by purpose. So any suggestions would be really appreciated. One more thing, drupal_mail, or any other, say for example, mail chimp, notify etc would be of interest. What I need is just a mail to be send to admin after submit from the code itself.

Thanks
You surely can send an email on the submit. 

See the code below. 

function my_module_action($form, &amp;$form_state) {
  drupal_set_message(t('Challenge Accepted'));
  $query = db_insert('challenges')
    -&gt;fields(array(
    'cid' =&gt; '$node-&gt;nid',
    'uid' =&gt; '$user-&gt;uid'
    ))
    -&gt;execute();
  $message = array('A new entry has been submitted');
  $to = 'example@example.com';
  $params = array(
    'body' =&gt; $body,
     'subject' =&gt; 'Website Information Request',
  );
  if (drupal_mail('my_module', 'some_mail_key', $to, language_default(), $params)) {
        drupal_set_message('Thanks, email sent.');    
    } else {
        drupal_set_message('Email not sent.');
    }
}


You also need this function. 

function my_module_mail($key, &amp;$message, $params) {
  $message['subject'] = $params['subject'];
  $message['body'] = $params['body'];
}


in drupal_mail(), we pass $params array which contains parameters to build the email. If your module sends multiple emails, you can differentiate them using the $key variable. 
But in this example, we simple assign message's variables from the direct $params variables. 
Note that $message (in your submit handler) needs to be an array of text that you need to send. 
For example, 

$body = array();
$body[] = 'Hello,';
$body[] = 'There is a new submission...';


This is because when the email gets sent, body content will be imploded by a new line character. Each value in the $body array will appear in a new line. 

Also, as a fine tuning, you won't need my_module_form function if you format your hook_menu function like this:

function my_module_menu() {
  $items = array();
  $items['my_module/form'] = array(
    'title' =&gt; 'My form', // We don't t() menu titles.
    'page callback' =&gt; 'drupal_get_form', // Directly call drupal_get_form...
    'page arguments' =&gt; array('my_module_my_form'), // ...with this argument.
    'access arguments' =&gt; array('access content'),
    'description' =&gt; t('My form'),
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}