Ask not what osTicket community can do for you - ask what you can do for osTicket community

Go Back   osTicket Forums > Project Tools > osTicket Bug Tracker > Bug

Issue Type Bug   Project osTicket Bug Tracker
Attachments Not Emailed When Creating New Ticket
Category Unknown
Affected Version 1.6 Stable
Priority 5 - Medium
Status Unconfirmed
Fixed Version (none)
Submitted 08-07-2011
Assigned Users (none) Tags (none)

issueid=262 08-07-2011 09:01 PM
Junior Member
Attachments Not Emailed When Creating New Ticket

In the staff Create Ticket screen, there is an option to attach a file. The file does properly attach to the ticket, however, the attachment is not included in the email notification that is sent to the user.

I discovered that this was happening because in class.ticket.php, the create_by_staff() method calls the create() method, which calls the uploadAttachment() method, which calls the move_uploaded_file() function, which results in the tmp file being deleted during the ticket creation process. Therefore, when the script tries to email the attachment after the ticket is created, the file is no longer there.

I fixed this by moving the attachment handling logic higher up in the script, immediately before the create() method is called and making a copy of the original tmp file. Thus, when move_uploaded_file deletes the original tmp file, we still have another copy of the file to work with, when calling the $email->send() method. Here's the code I came up with:

PHP Code:
        //Email attachment when attached AND if emailed attachments are allowed!
        //BSK This attachment logic was moved up in the script, so it executes before the create() method. This was necessary since create() deletes the attachment.
        
$file=null;
        
$attachment=$_FILES['attachment'];
        if((
$attachment && is_file($attachment['tmp_name'])) && $cfg->emailAttachments()) {
            
copy($attachment['tmp_name'], $attachment['tmp_name'] . '_copy'); // BSK Make a copy of the attachment
            
$file=array('file'=>$attachment['tmp_name'] . '_copy''name'=>$attachment['name'], 'type'=>$attachment['type']);
        }
        if((
$ticket=Ticket::create($var,$errors,'staff',false,(!$var['staffId'])))){  //Staff are alerted only IF the ticket is not being assigned. 
Reply


Issue Tools
Subscribe to this issue

All times are GMT -4. The time now is 03:03 AM.