Ask Andy

<div class="imrgt">
<div><img src="/sites/default/files/askandy/askandy.jpg" alt="Professor Andy Newsam" width="250" height="210" /></div>
<div class="credit">Professor Andy Newsam</div></div>
<p>
Discover more about the Universe with the NSO's resident astronomer, Professor Andrew Newsam. Andy is a senior lecturer in astronomy education at <a href="http://www.ljmu.ac.uk/" target="_blank">Liverpool John Moores University</a>, and has made several appearences on TV and Radio, including a spot of planet observing on <a href="/news/2010/bluepeter">Blue Peter</a>.
<p>
If you would like to ask a question about any aspect of Astronomy, then please do so in the box below. When he has a moment, Andy will record video answers to the best questions and they will be posted at the following link.
<p style="margin-left:20px;">
<a href="/askandy/answers"><img src="/sites/default/files/astro/lt/warrow.jpg" style="vertical-align:middle;">
View Andy's answers</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small>(Please look to see if your question has already been asked.)</small>
<p style="margin-top:30px;">

<?php
/**
* Create a form with a single text field and submit button.
*/
function askandy_form() {

$form['form_id'] = array(
'#type' => 'hidden',
'#value' => 'askandy_form',
);
$form['#id'] = 'askandy-form';

$form['question'] = array(
'#type' => 'textfield',
'#title' => 'Enter your Question for Andy',
'#size' => '50',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit Question',
);
return $form;
}

/**
* Create the hook_mail function
* Required in Drupal 6
*/
function askandy_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 askandy_form_submit($form, &$form_state) {

global $user;

$valid_email = 'askandy@schoolsobservatory.org.uk';
$question = check_plain($form_state['values']['question']);
$from = check_plain($user->mail);
$body = 'Ask Andy Question = ' . $question;

$params = array(
'body' => $body,
'subject' => 'Ask Andy Question from ' . $user->name,
);

//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('askandy_form', 'some_mail_key', $valid_email, language_default(), $params, $from, TRUE))
{
drupal_set_message('Thank you. Your question has been sent to Andy');
} else {
drupal_set_message('There was an error sending your question');
}
}

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