PDA

View Full Version : Editing Class.misc.php to enable mail from windows 2003 server


poulin
04-21-2008, 07:25 PM
:confused:So after browsing the forums for a while, I found a answer I thought would enable me to send autoresponses to users who submitted a ticket. My question is, why does the code inside the class.misc.php look a bit cryptic (like characters other than standard PHP code ?). Am I missing something here or what.....is see '0s' within the code as I read it in notepad.....I have never seen this in other php programs... I may ju8st be acting a complete noob :D- but why does this look different (with the '0's randomly found throughout the page ? Thanks,
J.P
<------------Start of class.misc.php ------>

<?php
/************************************************** *******************
class.misc.php

Misc collection of useful generic helper functions.

Peter Rotich <peter@osticket.com>
Copyright (c) 2006,2007,2008 osTicket
http://www.osticket.com

Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.

vim: expandtab sw=4 ts=4 sts=4:
$Id: $
************************************************** ********************/
class Misc {

function randCode($len=8) {
return substr(strtoupper(base_convert(microtime(),10,16)) ,0,$len);
}

/* Helper used to generate ticket IDs */
function randNumber($len=6,$start=false,$end=false) {

mt_srand ((double) microtime() * 1000000);
$start=(!$len && $start)?$start:str_pad(1,$len,"0",STR_PAD_RIGHT);
$end=(!$len && $end)?$end:str_pad(9,$len,"9",STR_PAD_RIGHT);

return mt_rand($start,$end);
}

/* misc date helpers...this will go away once we move to php 5 */
function db2gmtime($var){
global $cfg;
if(!$var) return;

$dbtime=is_int($var)?$var:strtotime($var);
return $dbtime-($cfg->getMysqlTZoffset()*3600);
}

/*Helper get GM time based on timezone offset*/
function gmtime() {
return time()-date('Z');
}

/* Helper to send an alert to admin EMAIL */
function alertAdmin($subj,$msg) {
global $cfg;
$to=$cfg?$cfg->getAdminEmail():ADMIN_EMAIL;
$from=$cfg?$cfg->getAlertEmail():ADMIN_EMAIL;
//Send alert to admin.
Misc::sendmail($to,$subj,$msg,$from);
}

/* Send email out after minor cleanups..*/
function sendmail($to, $subject, $message, $fromaddress,$fromname='', $xheaders = '') {
//TODO: provide an option to use SMTP server. Log all outgoing emails??

$eol="\n";
$fromname=$fromname?$fromname:$fromaddress;
//do some cleanup...avoid stupid errors.
$to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
$subject=preg_replace("/(\r\n|\r|\n)/s",'', trim($subject));
$message = preg_replace("/(\r\n|\r)/s", "\n", trim($message));
#Headers
$headers .= "From: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Reply-To: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol;
$headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol;
$headers .= "X-Mailer: osTicket v 1.6".$eol;
if($xheaders) { //possibly attachments...does mess with content type
$headers .= $xheaders;
}else{
$headers .= "Content-Type: text/plain; charset=utf-8".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol;
}
//echo "[$to,$subject,$message ".$headers.']';
mail($to,$subject,$message,trim($headers));
}

}
?>




<---end -->

rgwillia
04-22-2008, 06:16 PM
I just installed the software for the first time today and after a little bit of messing around with the software I was able to get email responses working.

First I tried changing my php.ini file so that the SMTP server was set to an exchange SMTP server in our organization. (not under my control) I was unable to get that to work so I switched it to using localhost again.

What I ended up doing was using the IIS SMTP Virtual Server on the local computer. I went to properties -> access -> relay and I gave 127.0.0.1 as well as the local ip address relay rights. Under the Security tab I set my IUSR_LOCALSERVERNAME account to give it access to send mail. I am not sure if I needed to follow this step but I figured it could not hurt (esp since the server is internal)

Under delivery and advanced I setup a Smart host to point to our exchange smtp server. I also enabled logging on the general tab. This allowed me to watch the log file in c:\windows\system32\logfiles\smtpsvc1 to see that the smtp commands were going out to the smart host.

After I did all of that I was able to get the mail services working on the server.