Send Email to All Staff in osTicket v1.6 RC5

Have you ever wanted to send email that contains of an announcement to all of your staff from osTicket System? Well, here is the solution I created on osTicket v1.6 RC5. This modification will add a new sub tab named Send Email to Staff under the Emails tab in Admin Panel, also a new email template named Email to All Staff which is the email Subject and Body that contains of your email that you will send to all of your staff. You have to define first this two textboxes of the email template for this purpose from Emails -> Templates menu in Admin Panel.

  1. First of all, alter your ost_email_template table by using this following SQL script. Please note that the ost_ is the table prefix name. It could be different with yours. In case it differs with yours, please adjust it by yourself!

    ALTER TABLE ost_email_template
    ADD COLUMN `alert_all_staff_subj` varchar(255) NOT NULL,
    ADD COLUMN `alert_all_staff_body` text NOT NULL;
  2. Create a new file and copy paste this following code into it, and then save it as sendemailtostaff.inc.php and put this file into your \include\staff\ sub directory.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    
    <?php
     
    /**
     * @author Masino Sinaga, http://www.openscriptsolution.com
     * @copyright October 29, 2009
     */
     
    if(!defined('OSTADMININC') || !$thisuser->isadmin()) die('Access Denied');
     
    global $cfg;
    $tplId=$cfg->getDefaultTemplateId();
    $sql='SELECT alert_all_staff_subj,alert_all_staff_body FROM '.EMAIL_TEMPLATE_TABLE.
         ' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId);
    if(($resp=db_query($sql)) && db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){
    	if ($subj!='' && $body!='') {	
      	include_once(INCLUDE_DIR.'class.email.php');
    	  $helpdesk_email=$cfg->getDefaultEmail();
        $sqls = 'SELECT DISTINCT(email) FROM '.STAFF_TABLE.'';
        if (($ress=db_query($sqls)) && db_num_rows($ress)) {
          while(list($email)=db_fetch_row($ress)) {
            $helpdesk_email->send($email,$subj,$body);
          }
        }
        echo 'Email successfully sent!';	
      } else {
        echo 'Email failed sent. Check the Send Email to All Staff section from your Email Template ';
      }
    } else {
      echo 'Failed while getting email template. ';
    }
     
    ?>
  3. Open your \include\staff\template.inc.php file, and find this code:

    29
    30
    31
    
            <div class="msg">User</div>
            <table width="100%" border="0" cellspacing=0 cellpadding=2 class="tform tpl">
                <tr class="header"><td colspan=2 >New Ticket Autoresponse</td></tr>

    before the first line of that code, please insert this following code:

    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    
    	<div class="eas">Email to All Staff</div>
            <table width="100%" border="0" cellspacing=0 cellpadding=2 class="tform tpl">
                <tr class="header"><td colspan=2 >Send Email to All Staff</td></tr>
                <tr class="subheader"><td colspan=2 >
                    Email to all of your staff
    		Meant to send an email to all of your staff (including manager) without any exception.</td>
                    </tr>
                <tr>
                    <th>Subject:</th>
                    <td><input type="text" size="65" name="alert_all_staff_subj" value="<?=$tpl['alert_all_staff_subj']?>">
                    &nbsp;<font class="error">&nbsp;<?=$errors['alert_all_staff_subj']?></font></td>
                </tr>
                <tr>
                    <th>Body:</th>
                    <td>
                        <textarea rows="7" cols="75" name="alert_all_staff_body"><?=$tpl['alert_all_staff_body']?></textarea>
                        &nbsp;<font class="error">&nbsp;<?=$errors['alert_all_staff_body']?></font></td>
                </tr>
            </table>
            </div>
  4. Open your include\class.msgtpl.php file, and find this code:

    83
    
            $fields['name']     = array('type'=>'string',   'required'=>1, 'error'=>'Name required');

    then replace with this following code:

    83
    84
    85
    86
    
            $fields['name']     = array('type'=>'string',   'required'=>1, 'error'=>'Name required');
            //Send alert sent to all staff
            $fields['alert_all_staff_subj']  = array('type'=>'string',   'required'=>1, 'error'=>'Subject required');
            $fields['alert_all_staff_body']  = array('type'=>'string',   'required'=>1, 'error'=>'Template message required');

    Find again this code:

    124
    
                     ',notes='.db_input(Format::striptags($var['notes'])).

    then replace with this following code:

    124
    125
    126
    
                     ',notes='.db_input(Format::striptags($var['notes'])).
                     ',alert_all_staff_subj='.db_input(Format::striptags($var['alert_all_staff_subj'])).
                     ',alert_all_staff_body='.db_input(Format::striptags($var['alert_all_staff_body'])).

    Find again this code:

    190
    
                     ',notes='.db_input('New template: copy of '.$info['name']).

    then replace with this following code:

    190
    191
    192
    
                     ',notes='.db_input('New template: copy of '.$info['name']).
                     ',alert_all_staff_subj='.db_input(Format::striptags($var['alert_all_staff_subj'])).
                     ',alert_all_staff_body='.db_input(Format::striptags($var['alert_all_staff_body'])).
  5. Open your \scp\admin.php file, and find this code:

    241
    242
    
            case 'templates':
               include_once(INCLUDE_DIR.'class.msgtpl.php');

    before the first line of that code, please insert this following code:

    240
    241
    
            case 'sendemailtostaff':
    	    break;

    find again this code:

    621
    622
    
        case 'email':
        case 'templates':

    then replace with this following code:

    621
    622
    623
    
        case 'email':
        case 'sendemailtostaff':
        case 'templates':

    Find again this code:

    628
    
            $nav->addSubMenu(array('desc'=>'Templates','href'=>'admin.php?t=templates','title'=>'Email Templates','iconclass'=>'emailTemplates'));

    after that line, please insert this following code:

    629
    
    	$nav->addSubMenu(array('desc'=>'Send Email to Staff','href'=>'admin.php?t=sendemailtostaff','title'=>'Send Email to Staff','iconclass'=>'newEmail'));

    Find again this code:

    636
    637
    
                case 'templates':
                    $page='templates.inc.php';

    before the first line of that code, please insert this following code:

    635
    636
    637
    
           	    case 'sendemailtostaff':
           	        $page='sendemailtostaff.inc.php';
           	        break;

Have a nice code!

Share

1,535 viewsPrint This Post Print This Post

Comments

  1. Theo Milligan says:

    Hi.
    Thanks for the script I will be finding it usfull. Only one problem
    I can’t send the message via template.
    I created a template based on an existing one, saved it. Its there and I can see it.
    when i select the “send email to all staff” a message comes up “Email failed sent. Check the Send Email to All Staff section from your Email Template”. I check the template and can’t see any method of checking the template other than to edit the template.
    Any help would be greatfull.
    Cheers

  2. Question says:

    I’m using 1.6 ST and this module doesn’t seem to be working. Are there more tweaks needed for 1.6 ST instead of RC 5?

  3. Question says:

    Guess I should have mentioned the problem I’m having. While trying to insert setup my “Email to All Staff” template, I’m unable to save the changes because of a DB error. The error is:

    “Unknown column ‘alert_all_staff_subj’ in ‘field list’”

    I clearly have the alert_all_staff_subj field inserted into my ost_email_template, so I’m not sure why it’s throwing the error. I ran the SQL code that you have above to insert the two fields.

    Any input on the matter is much appreciated.

    P.S. Thank you for this mod, it’s very useful.

  4. John Malia says:

    Masino,

    I’m experiencing the same behaviors that Theo Milligan above is experiencing. Is there a solution published somewhere that I haven’t found?

    Thanks in advance for your help,

    John 88{Q

  5. rizky says:

    mas mau tanya.
    saya dapat tugas dr atasan utk mempelajari osticket. saya udah berhasil install tp pakai xampp localhost. setelah saya coba ternyata tidak bisa kirim email jika buat ticket baru. apakah ada settingan lain jika saya pakai localhost?
    mohon bantuannya, trims.

Speak Your Mind

*


*