<?php

require('message.inc');


class Contact_Mail extends Message {
	
	private $to = 'Martin Stadler <martin@siarp.de>, Tilman Walther <tilman@tilman.de>';
	private $subject = 'Post für Beethoven2000';
	private $from = 'Beethoven2000 Kontaktformular <abi@beethoven2000.de>';
	
	/**
	 * Sendet die Mail mit den Übergebenen Parametern.
	 */
	function __construct ($name, $address, $message) {
		
		if ($this->contains_spam_hints($name . $address . $message, array($name, $address))) {
			$this->spam = true;
			return true;
		}
		
		/* check for missing '@' in address as a spam hint */
		/* XXX dirty */
		if (!empty($address) && strpos($address, '@') === false) {
			$this->spam = true;
			return true;
		}

		$header  = 'MIME-Version: 1.0' . "\r\n";
		$header .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
		$header .= 'From: ' . $this->from . "\r\n";
				
		$contents = 'Name: ' . $name . "\r\n";
		$contents .= 'eMail: ' . $address . "\r\n";
		$contents .= "\r\n--------\r\n";
		$contents .= $message;
		
		if (!mail($this->to, $this->encode($this->subject), $contents, $header)) {
			$this->error = true;
		}
	}

	private function encode ($text) {
		return '=?UTF-8?B?' . base64_encode($text) . '?=';
	}
}

?>