By anilshrish on
I have a custom form in my module,which includes only three fields (Title, URL, email). Now how to send a email to the person who entered that form saying your form has been submitted (or any message).
My code :
/**
* implements hooks_menu
*/
function planet_extension_menu(){
$items['planetext']=array(
'title' => t('DEMO Planet Extension'),
'description' => 'Feeds aggregation ',
'page callback' => 'drupal_get_form',
'page arguments' => array('planet_extension'),
'access callback' => TRUE,
);
return $items;
}
// callback function
function planet_extension($form,&$form_submit){
$form['url']=array(
'#title' => 'URL',
'#type' => 'textfield',
'#required' => TRUE,
'#size' => 35,
'#description' => t('Enter the URL'),
'#attributes' =>array('placeholder' => t('www.example.com'))
#'#default_value' => t('www.example.com')
);
$form['title']=array(
'#title' => 'Title',
'#type' => 'textfield',
'#required' => TRUE,
'#size' => 35,
'#description' => t('Enter the Title'),
'#attributes' =>array('placeholder' => t('Title'))
);
$form['email']=array(
'#title' => 'email',
'#type' => 'textfield',
'#required' => TRUE,
'#size' => 35,
'#description' => t('Enter you valid email'),
'#attributes' =>array('placeholder' => t('example@example.com'))
);
$form['submit']=array(
'#type' =>'submit',
'#value' => 'Submit',
);
return $form;
}
//below is the form submission function
function planet_extension_submit($form,$form_state){
//store the values entered in form into variables
$values = array(
'url' => $form_state['values']['url'],
'title' => $form_state['values']['title'],
'email' => $form_state['values']['email'],
);
//insert the variables into the table
$insert = db_insert('planet_extension')
-> fields(array(
'url' => $values['url'],
'title' => $values['title'],
'email' => $values['email'],
))
->execute();
drupal_set_message(t('Form submitted. Check your email for varification')); //custom message after form submission is successful
}
Comments
<?phpfunction
You need to do two things to send emails:
1) Set the mail up in an implementation of hook_mail()
2) Send the mail using drupal_mail()
Contact me to contract me for D7 -> D10/11 migrations.
Thank you so much Jay
is there anyway i can attach file to my mail ? Thank you
Try this
Try this https://drupal.org/project/mimemail