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:
<?php
global $user;
function my_module_help($path, $arg) {
switch ($path) {
case "admin/help#formtest":
return '<p>' . t("Test form for accept challenge") . '</p>';
break;
}
}
function my_module_menu() {
$items = array();
$items['my_module/form'] = array(
'title' => t('My form'),
'page callback' => 'my_module_form',
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => 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' => 'submit',
'#value' => 'Accept Challenge',
'#submit' => array('my_module_action'),
);
return $form;
}
function my_module_action($form, &$form_state) {
drupal_set_message(t('Challenge Accepted'));
$query = db_insert('challenges')
->fields(array(
'cid' => '$node->nid',
'uid' => '$user->uid'
))
->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