Simple helper function to send a mail

Public

Get raw version
php
  1. /**
  2.  * Helper to send a mail.
  3.  */
  4. function mycustomhelper_mail($to, $message_subject, $message_body) {
  5. // Get a sender mail address ("From").
  6. $default_from = 'from@example.com';
  7. $from = variable_get('system_mail', $default_from);
  8.  
  9. $message = array(
  10. 'id' => '_',
  11. 'to' => $to,
  12. 'subject' => $message_subject,
  13. 'body' => array($message_body),
  14. 'headers' => array(
  15. 'From' => $from,
  16. 'Sender' => $from,
  17. 'Return-Path' => $from,
  18. ),
  19. );
  20. $system = drupal_mail_system('', '');
  21. $message = $system->format($message);
  22.  
  23. // Send it.
  24. if ($system->mail($message)) {
  25. return TRUE;
  26. }
  27. else {
  28. return FALSE;
  29. }
  30. }