user_name,$_REQUEST['name'],$_REQUEST['description'],$mail_server,$mail_server_username,$mail_server_password);
function sendmail($to,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password)
{
global $adb,$root_directory,$mod_strings;
	$sql = $_REQUEST['query'];
	$result= $adb->query($sql);
	
	$noofrows = $adb->num_rows($result);
	$dbQuery = 'select attachments.*, activity.subject, emails.description  from emails inner join crmentity on crmentity.crmid = emails.emailid inner join activity on activity.activityid = crmentity.crmid left join seattachmentsrel on seattachmentsrel.crmid = emails.emailid left join attachments on seattachmentsrel.attachmentsid = attachments.attachmentsid where crmentity.crmid = '.$_REQUEST['return_id'];
        $result1 = $adb->query($dbQuery) or die("Couldn't get file list");
	$temparray = $adb->fetch_array($result1);
	$notequery = 'select  attachments.*, notes.notesid, notes.filename,notes.notecontent  from notes inner join senotesrel on senotesrel.notesid= notes.notesid inner join crmentity on crmentity.crmid= senotesrel.crmid left join seattachmentsrel  on seattachmentsrel.crmid =notes.notesid left join attachments on seattachmentsrel.attachmentsid = attachments.attachmentsid where crmentity.crmid='.$_REQUEST['return_id'];
	$result2 = $adb->query($notequery) or die("Couldn't get file list");
	        $mail = new PHPMailer();
	
                $mail->Subject =$adb->query_result($result1,0,"subject");
		$DESCRIPTION = $adb->query_result($result1,0,"description");
		$DESCRIPTION .= '
';
		$DESCRIPTION .= ''.$adb->query_result($adb->query("select * from users where user_name='".$from."'"),0,"signature").'';
                $mail->Body    = nl2br($DESCRIPTION);
		$initialfrom = $from;
		$mail->IsSMTP();
if($mail_server=='')
{
        $mailserverresult=$adb->query("select * from systems where server_type = 'email'");
        $mail_server=$adb->query_result($mailserverresult,0,'server');
	$_REQUEST['server']=$mail_server;
}
		$mail->Host = $mail_server;
		$mail->SMTPAuth = true;
		$mail->Username = "";
		$mail->Password = "";
		$mail->From = $adb->query_result($adb->query("select * from users where user_name='".$from."'"),0,"email1");
		$mail->FromName = $initialfrom;
//		$mail->AddAddress($to);
		$mail->AddReplyTo($from);
		$mail->WordWrap = 50;
//store this to the hard disk and give that url
for($i=0;$i< $adb->num_rows($result1);$i++)
{
	$fileContent = $adb->query_result($result1,$i,"attachmentcontents");
	$filename=$adb->query_result($result1,$i,"name");
	$filesize=$adb->query_result($result1,$i,"attachmentsize");
	if(!@$handle = fopen($root_directory."/test/upload/".$filename,"wb")){}
	//chmod("/home/rajeshkannan/test/".$fileContent,0755);
	if(!@fwrite($handle,base64_decode($fileContent),$filesize)){}
	if(!@fclose($handle)){}
	//select 
	$mail->AddAttachment($root_directory."/test/upload/".$filename);//temparray['filename']) // add attachments
//	$mail->IsHTML(true);
//	$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
}
for($i=0;$i< $adb->num_rows($result2);$i++)
{
        $fileContent = $adb->query_result($result2,$i,"attachmentcontents");
        $filename=$adb->query_result($result2,$i,"name");
        $filesize=$adb->query_result($result2,$i,"attachmentsize");
        if(!@$handle = fopen($root_directory."/test/upload/".$filename,"wb")){}
        //chmod("/home/rajeshkannan/test/".$fileContent,0755);
        if(!@fwrite($handle,base64_decode($fileContent),$filesize)){}
        if(!@fclose($handle)){}
        //select
        $mail->AddAttachment($root_directory."/test/upload/".$filename);//temparray['filename']) // add attachments
//        $mail->IsHTML(true);
//        $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
}
$mail->IsHTML(true);
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
echo '
| '.$mod_strings['MESSAGE_ADD_USER_OR_CONTACT'].''; if($i>1 && $flag)echo "".$mod_strings['MESSAGE_MAIL_SENT_SUCCESSFULLY'].""; echo ' |