Skip to main content
<?php
     
/**
* 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('[email protected]'))
);
$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_mail('planet_extension', 'planet_extension_mail', $form_state['values']['email'], 'en', array('values' => $values));

        drupal_set_message(t('Form submitted. Check your email for varification'verification')); //custom message after form submission is successful
}


//implements hook_mail
function planet_extension_mail ($key, &$message, $params) {
  switch ($key) {
    case 'planet_extension_mail':
      $message['subject'] = t('Hello');
      $message['body'][] = t('Hello user');
      $message['body'][] = t('The main part of the message.');
      break;
  }
}

//implements hook_mail function planet_extension_mail ($key, &$message, $params) { switch ($key) { case 'planet_extension_mail': $message['subject'] = t('Hello'); $message['body'][] = t('Hello user'); $message['body'][] = t('The main part of the message.'); break; } }

<?php
 
/**
* 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('[email protected]'))
);
$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_mail('planet_extension', 'planet_extension_mail', $form_state['values']['email'], 'en', array('values' => $values));

        drupal_set_message(t('Form submitted. Check your email for varification')); //custom message after form submission is successful
}

//implements hook_mail function planet_extension_mail ($key, &$message, $params) { switch ($key) { case 'planet_extension_mail': $message['subject'] = t('Hello'); $message['body'][] = t('Hello user'); $message['body'][] = t('The main part of the message.'); break; } }

<?php    
/**
* 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'))
);
$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('[email protected]'))
);
$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_mail('planet_extension', 'planet_extension_mail', $form_state['values']['email'], 'en', array('values' => $values));

        drupal_set_message(t('Form submitted. Check your email for verification')); //custom message after form submission is successful
}


//implements hook_mail
function planet_extension_mail ($key, &$message, $params) {
  switch ($key) {
    case 'planet_extension_mail':
      $message['subject'] = t('Hello');
      $message['body'][] = t('Hello user');
      $message['body'][] = t('The main part of the message.');
      break;
  }
}
Source Link
shrish
  • 1.8k
  • 3
  • 19
  • 29

How do I send verification mail from my drupal custom module?

I have written a custom module, which can send simple mail. how do I send mail so that user should get the verification link or something similar.

<?php

/**
* 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('[email protected]'))
);
$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_mail('planet_extension', 'planet_extension_mail', $form_state['values']['email'], 'en', array('values' => $values));

        drupal_set_message(t('Form submitted. Check your email for varification')); //custom message after form submission is successful
}

//implements hook_mail function planet_extension_mail ($key, &$message, $params) { switch ($key) { case 'planet_extension_mail': $message['subject'] = t('Hello'); $message['body'][] = t('Hello user'); $message['body'][] = t('The main part of the message.'); break; } }