/**
* Create a custom php block
* Place the block in the rh column.
*/

/**
* Create a form with a single text field and submit button.
*/
function my_form() {

$form['email'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => '20',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Subscribe',
);
return $form;
}

/**
* Validate the form.
*/
function my_form_validate($form, &$form_state) {
$valid_email = $form_state['values']['email'];
if (!valid_email_address($valid_email)) {
form_set_error('email', 'Your email address -- ' . $valid_email . ' -- appears malformed');
}
}

/**
* Create the hook_mail function
* Required in Drupal 6
*/
function my_form_mail($key, &$message, $params) {

$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal'
);

foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}

$message['subject'] = $params['subject'];
$message['body'] = $params['body'];
}

/**
* Create the form submit function
*/
function my_form_submit($form, &$form_state) {

$valid_email = $form_state['values']['email'];
$from = 'test@example.com';
$body = 'New Email Sent = ' . $valid_email;

$params = array(
'body' => $body,
'subject' => 'This is a subject',
);

//NB First argument of the drupal_mail function must match the first part of the hook_mail function.
//Therefore the first argument is 'my_form' and the the mail hook is 'my_form_mail'
//For more info see:
//http://api.drupal.org/api/function/drupal_mail/6
//http://api.drupal.org/api/function/hook_mail/6

if (drupal_mail('my_form', 'some_mail_key', $valid_email, language_default(), $params, $from, TRUE))
{
drupal_set_message('An email has been sent to ' . $valid_email);
} else {
drupal_set_message('There was an error sending your email');
}
}

/**
* Return the form.
*/
return drupal_get_form('my_form');
?>