I created a very simple module that attaches a small form on the bottom of each node. When the form is submitted, I get:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, support@supportwebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/1.3.33 Server at deepbluedev.com Port 80

I get this error when I try to incorporate drupal_mail(), drupal_mail_send(), or, php's default mail()

HOWEVER

my contact module is installed, and I can successfully send mail using the default contact form.

Can anyone tell me why this is happening?

For references, here is the code for my module

<?php

// $Id

function contact_poster_menu() {
	$items = array();
	
	$items['contact_poster'] = array(
		'title' => t('Contact Poster Module'),
		'page callback' => 'contact_poster_page',
		'access arguments' => array('access content'),
		'type' => MENU_SUGGESTED_ITEM,		
	);
	
	return $items;
}

function contact_poster_page() {
	return drupal_get_form('contact_poster_form');	
}

function contact_poster_form($form_state) {
	$form = array();
	
	$form['email'] = array(
		'#type' => 'textfield',
		'#title' => t('Email'),
		'#required' => TRUE,
	);
	
	$form['message'] = array(
		'#type' => 'textarea',
		'#title' => 'Message',
		'#rows' => 4,
		'#required' => TRUE,	
	);
	
	$form['nodetitle'] = array(
		'#type' => 'hidden',
		'#value' => $node->title,
	);
	
	$form['submit'] = array(
		'#type' => 'submit',
		'#value' => 'Send',
	);
	
	return $form;
}

function contact_poster_form_validate($form_id, &$form_state) {
	//check if the email field is valid
	if(isset($form_values['values']['email'])) {
		if (!valid_email_address($form_values['values']['email'])) {
		   form_set_error('email', t('The e-mail address you specified is not valid.'));
		}
	}
}

function contact_poster_form_submit($form_id, &$form_state) {
	
	$author = user_load($node->uid);;
	$to = $author->mail;
	$from = $form_state['values']['email'];
	$body = $form_state['values']['message'];
	$nodetitle = $form_state['values']['nodetitle'];
	
	$headers = array(
    'MIME-Version'              => '1.0',
    'Content-Type'              => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer'                  => 'Drupal'
    );
	
	$message = array(
     //'id'       => $module .'_'. $key,
    'to'       => $to,
    'from'     => $from,
     //'language' => $language,
     //'params'   => $params,
    'subject'  => $nodetitle,
	'body'     => $body,
     //'body'  => array()
	 'headers' => $headers,
     );
	 
	 
  
  
	
	
	drupal_set_message(t('Your message has been successfully submitted.'));	
	drupal_mail('contact_poster', 'contact_poster_mail', $to, language_default(), $form['values'], $from);
	
	
	/*$to      = $author->mail;
	$subject = 'Gastonia.com - Response to your post '.$nodetitle;
	$message = $body;
	$headers = 
		'From: '.$from . "\r\n" .
    	'Reply-To: '.$from . "\r\n" .
    	'X-Mailer: PHP/' . phpversion();

        //drupal_mail_send($message)
	//mail($to, $subject, $message, $headers); 
	//print $message;
	*/ 		
}

?>

Comments

JimNastic’s picture

I have also created a module which sends an email including information entered in a form. I have a similar problem and have contacted the shared hosting company (strato.de) for advice.

Searching the community I have seen some tips on changing .htaccess here:
http://www.csdesignco.com/content/remedy-internal-server-error-500-drupal-6
None of these suggestions helped in my case.

Any other tips from the community?

JimNastic’s picture

I checked the logfiles and found this error "malformed header from script. Bad header=No recipient addresses found i: index.php,"

JimNastic’s picture

I had an incorrectly formed copy of the drupal_mail() function call lower in my module. (I thought I had commented it out)