Enquiries: / +44 (0)20 7193 3323

Testing drupal_mail() from a PHP block

Sometimes it's useful to test the sending of an email to a specific address w/o configuring/installing any module to do such thing. For that I personally use a PHP snippet that can be executed from the PHP block that comes from the devel module.

Drupal 6.x:

$to = '';
$message = drupal_mail('no_module', 'key_not_used', $to, language_default(), array(), null, FALSE);
$message['subject'] = 'Test message';
$message['body'] = 'This is a test message';
// Send e-mail.

Drupal 7.x:

$my_module = 'no_module';
$my_mail_token = 'no_token';
$from = variable_get('site_mail', ini_get('sendmail_from'));
$message = array(
  'id' => $my_module . '_' . $my_mail_token,
  'to' => '',
  'subject' => 'test',
  'body' => 'test',
  'headers' => array(
    'From' => $from, 
    'Sender' => $from, 
    'Return-Path' => $from,
$system = drupal_mail_system('no_module', $my_mail_token);
if ($system->mail($message)) {
else {
Posted by ariel on April 18th, 2011
Comments: 1

I don't care about this, now

I don't care about this, now i'm earning average 5000$ a month. There is tricky way i found on the web. If you want to learn it too, just type in google: Hatvesu's Earning Online Strategy

Post new comment

The content of this field is kept private and will not be shown publicly.