<?php

function lens_mail($to,$subj,$body,$attach=false,$desc='attachment',$type='text/plain')
{
global $DB;

	$to = trim(str_replace('\n',' ',$to));
	$subj = trim(str_replace('\n',' ',$subj));
	$body .= MAIL_SIGNATURE;
	if (!$attach) {
		$hdr = "From: ".MAIL_FROM."\n";

		$ok = @mail($to,$subj,$body);
	} else {
		include_once(dirname(__FILE__).'/mime.inc.php');
		$m = new CMIMEMail($to,MAIL_FROM,$subj);
		$m->mailbody('test');//,'<b>Test</b>');
		$m->attach($desc, $type,$attach);
		$ok = $m->send();
	}
	
	if (!$ok) {
		$to = $DB->qstr($to);
		$subj = $DB->qstr($subj);
		$body = $DB->qstr($body);
		$t = $DB->DBTimeStamp(time());
		$a = empty($attach) ? 'F' : 'T';
		$DB->Execute("insert into remail(when,to,subj,body)values($t,$to,$subj,$body)");
	}
		
}
?>