How to send emails in Drupal programmatically

Posted by admin on Tue, 01/31/2017 - 17:53

The easiest way to simply send email in Drupal programmatically.

drupal_mail('system', 'mail', 'yourmail@gmail.com', language_default(), array(
  'context' => array(
    'subject' => 'Awesome subject',
    'message' => 'Email body message here',
  )
));

Just replace yourmail@gmail.com with email of recipient, put subject and message - and your email would be sent immediately.

Another way - more complicated, but more complex - is to use hook_mail.
First what you need - is to declare in your custom module hook_mail:

/**
 * Implements hook_mail().
 */
function yourmodule_mail($key, &$message, $params) {
  if ($key == 'my_example') {
    $message['subject'] = 'Email subject';
    $message['body'][] = "This is a email message \n Some variable = {$params['some_var']}";
  }
}

This looks a little bit crazy, but this is extendable by other module with hook_mail_alter.

Then to send email using this hook - you just need to call drupal_mail with next parameters:

drupal_mail('yourmodule', 'my_example', 'to-user@mail.com',
language_default(), array('some_var' => 'Some value'));

Using this will send a email to to-user@mail.com using your hook_mail and with parameter some_var set to 'Some value'.

Tags: 
×

Hey! Don't miss a new cool stuff!

Comments

enetibliole (not verified)

slot games slots games no deposit casino real money casino

enetibliole (not verified)

casino games http://onlinecasinogamespcx.com/ - slot games world class casino slots online gambling

enetibliole (not verified)

http://onlinecasinogamespcx.com/ online slots http://onlinecasinogamespcx.com/ - real money casino casino play

enetibliole (not verified)

free online slots http://onlinecasinogamespcx.com/ - free casino games play online casino online casino gambling

enetibliole (not verified)

free online slots http://onlinecasinogamespcx.com/ - free casino games play online casino online casino gambling

enetibliole (not verified)

vegas casino slots slots free no deposit casino

inticleni (not verified)

free casino http://onlinecasinosw.com/ - online casino real money cashman casino slots cashman casino slots online casinos

enetibliole (not verified)

casino game http://onlinecasinogamespcx.com/ - casino game casino games casino online online casino real money

inticleni (not verified)

casino blackjack play slots online slots games free casino games http://onlinecasinosw.com/ - free online slots

enetibliole (not verified)

casino bonus codes http://onlinecasinogamespcx.com/ online casino bonus free slots games casino online

enetibliole (not verified)

casino bonus codes http://onlinecasinogamespcx.com/ online casino bonus free slots games casino online

enetibliole (not verified)

casino bonus codes http://onlinecasinogamespcx.com/ online casino bonus free slots games casino online

inticleni (not verified)

world class casino slots http://onlinecasinosw.com/ - casino bonus codes online casino real money free casino games online

inticleni (not verified)

world class casino slots http://onlinecasinosw.com/ - casino bonus codes online casino real money free casino games online

inticleni (not verified)

world class casino slots http://onlinecasinosw.com/ - casino bonus codes online casino real money free casino games online

Pigzhp r (not verified)
enetibliole (not verified)

http://onlinecasinogamespcx.com/ free slots games http://onlinecasinogamespcx.com/ - cashman casino slots online casino slots

inticleni (not verified)

free casino vegas slots online real money casino free casino slot games

inticleni (not verified)

free casino vegas slots online real money casino free casino slot games

enetibliole (not verified)

slots games http://onlinecasinogamespcx.com/ free casino games online play casino online casino gambling

inticleni (not verified)

http://onlinecasinosw.com/ slots free http://onlinecasinosw.com/ - big fish casino free slots games

inticleni (not verified)

http://onlinecasinosw.com/ slots free http://onlinecasinosw.com/ - big fish casino free slots games

inticleni (not verified)

http://onlinecasinosw.com/ slots free http://onlinecasinosw.com/ - big fish casino free slots games

inticleni (not verified)

http://onlinecasinosw.com/ slots free http://onlinecasinosw.com/ - big fish casino free slots games

inticleni (not verified)

casino blackjack http://onlinecasinosw.com/ online casinos free casino slot games best online casinos

enetibliole (not verified)

http://onlinecasinogamespcx.com/ play slots online world class casino slots slots games free world class casino slots

enetibliole (not verified)

http://onlinecasinogamespcx.com/ play slots online world class casino slots slots games free world class casino slots

enetibliole (not verified)

http://onlinecasinogamespcx.com/ play slots online world class casino slots slots games free world class casino slots

inticleni (not verified)

http://onlinecasinosw.com/ play online casino online casinos real money casino casino online

inticleni (not verified)

http://onlinecasinosw.com/ play online casino online casinos real money casino casino online

enetibliole (not verified)

slots games free http://onlinecasinogamespcx.com/ casino blackjack casino real money online casino games

enetibliole (not verified)

slots games free http://onlinecasinogamespcx.com/ casino blackjack casino real money online casino games

inticleni (not verified)

casino bonus codes casino slots cashman casino slots free online slots

inticleni (not verified)

casino bonus codes casino slots cashman casino slots free online slots

inticleni (not verified)

casino bonus codes casino slots cashman casino slots free online slots

enetibliole (not verified)

free online slots best online casinos online slots vegas slots online

enetibliole (not verified)

free online slots best online casinos online slots vegas slots online

inticleni (not verified)

online gambling free online slots free slots games

inticleni (not verified)

online gambling free online slots free slots games

inticleni (not verified)

online gambling free online slots free slots games

inticleni (not verified)

online gambling free online slots free slots games

inticleni (not verified)

online gambling free online slots free slots games

enetibliole (not verified)

online casinos casino games big fish casino casino bonus codes http://onlinecasinogamespcx.com/ - free casino

enetibliole (not verified)

online casinos casino games big fish casino casino bonus codes http://onlinecasinogamespcx.com/ - free casino

inticleni (not verified)

online casino games http://onlinecasinosw.com/ online casino games online casino slots games free

inticleni (not verified)

online casino games http://onlinecasinosw.com/ online casino games online casino slots games free

inticleni (not verified)

online casino games http://onlinecasinosw.com/ online casino games online casino slots games free

inticleni (not verified)

online casino games http://onlinecasinosw.com/ online casino games online casino slots games free

enetibliole (not verified)

casino game http://onlinecasinogamespcx.com/ - play slots play casino online casino gambling free casino games

inticleni (not verified)

free slots http://onlinecasinosw.com/ slots games free casino slot games slots online

Add new comment