Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/email_class.inc
<?php

class Email {
    
    var $params;
    
    
    function Email () {
        
        ////Configure your email variables below
        //$this->params['host'] = 'smtp.callatg.com';
        $this->params['host'] = 'mail.speakeasy.net';
        $this->params['auth'] = 'true';

        $this->params['username'] = 'teddk';
        $this->params['password'] = 'zooplew';

        include_once ('Mail.php');
    
    }
    
    
    
    function email_notification_of_report_to_users ( $from_user_id, $user_id_array, $subject, $message, $report_type_id, $edit_report_id )   {
        GLOBAL $system_directory;
        
        $from_user_array = pull_user_variables ( $from_user_id );
        
        if ( is_array ( $user_id_array ) )  {
            foreach ( $user_id_array AS $cur_user_id )  {

                $user_array = pull_user_variables ( $cur_user_id['user_id'] );                    

                //$email_message = "The following referral was made "; 
                $email_message = "<a href=\"http://".$_SERVER["SERVER_NAME"].$system_directory."report.php?report_type_id[".$report_type_id."]=".$report_type_id."&edit_report_id[$edit_report_id]=".$edit_report_id."&form_status=not_submitted\">";
                $email_message .= "Click here to view referral</a><br/>";
                //$email_message .= "<p><a href=\"http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."?selected_report=".$selected_report."&form_submitted=selected_report&focus=yes\">";
                //$email_message .= "Click Here</a> to view the complete discussion.</p>"; 
                //$email_message .= "<p><b>".$subject."</b></p>";
                $email_message .= "<p>".$subject.' - '.$message."</p>";


                $em = new Email();


                    if ( $em->validate_email_address ( $user_array['user_email'] ) != -1 ) {
                        $em->email_message ( 
                            $user_array['user_email'], 
                            $user_array['user_name_first']." ".$user_array['user_name_last'],
                            $from_user_array['user_email'],
                            $from_user_array['user_name_first']." ".$from_user_array['user_name_last'], 
                            $email_message,
                            $subject.' - '.$message 
                        );                     

                    }        

                }
            }
            
    }   



    function email_message ( $vetted_to_email_address, $vetted_to_display_name, $vetted_from_email_address,
    $vetted_from_display_name, $vetted_message, $vetted_subject = "" )    {

    //echo "vetted from name is: ".$vetted_from_display_name."<p>";
    
        
        if ( !$vetted_subject ) {
            $location_of_first_return = strpos ( $vetted_message, "\n" );
            if ( $location_of_first_return > 1 && $location_of_first_return < 100 ) {
                $vetted_subject = substr ( $vetted_message, 0, $location_of_first_return );
            }
            else {
                
                $vetted_subject = "Message From - ".$vetted_to_display_name;
            }
        } 

        $message = "<html><head><title>".$vetted_subject."</title></head><body>";
        $message .=  $vetted_message;
        $message .= "</body></html>";


        $to = $vetted_to_email_address;
        
        $headers['MIME_VERSION'] = '1.0';
        $headers['Content-type'] = 'text/html; charset=iso-8859-1';
        $headers['From'] = $vetted_from_display_name." <".$vetted_from_email_address.">";
        $headers['To'] = $vetted_to_display_name." <".$vetted_to_email_address.">";
        $headers['Subject'] = $vetted_subject;

        //echo $to."<p>".$subject."<p>".$message."<p>".$headers."<p>";
        //echo "<p>".$message."<p>"."<p>";
        //Using external SMTP server
        
        
        //$this->params['host'] = 'sy.net';
        //$this->params['auth'] = 'true';
        //$this->params['username'] = '';
        //$this->params['password'] = '';

        $mail_object =& Mail::factory('smtp', $this->params);
        $mail_object->send ( $to, $headers, $message );      
        //echo "headers are: <p>".var_dump($headers)."<p>";
        
    }
    
    
    
    function validate_email_address ( $emailform )  {
        GLOBAL $error_message;


        if ( eregi( "^[-a-z0-9_]+[-a-z0-9_.]*@[-a-z0-9_]+.[-a-z0-9_.]+$", $emailform) && strlen ($emailform) < 51 ) {
                    //Do nothing
        }    
        else {    
            $error_message.= "\"Email\" must be letters, numbers, and/or the characters \".\", \"@\", \"-\", and no more than 50 characters
            long<br>"; $error_message = "yes"; $emailform= -1;
            
	    }

        return $emailform;

    }


}
?>
Return current item: Homeless Mangement Information System