Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Send copy of every email send by OsTicket to cient to a static email address

Dear Forum,

I am using the smtp mail function and would need a copy of every email send by OsTicket being sent to a static email address.

For example lets asume I install osTicket on www.mydomain.org. Then I would simply need a copy of all emails generated throug osTicket to copy@mydomain.org.

As this email always stays the same it can be simply copied somewhere in the php code. In my old installation it worked like this, but as I have no idea of php I would need some advise where to add copy@mydomain.org in the new code of osTicket.

Thanks a lot in advance for your help

Stefan

Comments

  • I think that you would want to edit:

    /include/class.email.php
    Edit the following functions: send, sendAutoReply, sendAlert on lines 148-165.  Alteranatively it may be easier to simple append the second email address to the $to var.  say on line 147 maybe something like:

    $to .=",copy@mydomain.org";

    I have no idea if this will work... but it might.  And when you upgrade you will have to re-do this change.

    note: the line number may be wrong since you did not provide the version # of osT you are running.

  • Hi Ntozier,

    thanks a lot for your advise. I just tried the change but received the following error message:

     Parse error: syntax error, unexpected T_CONCAT_EQUAL, expecting ')' in /www/htdocs/wxxxxxx/support/include/class.email.php on line 148

    In my old osTicket Version the changes are at to places:

    ...
     //do some cleanup
            $eol="\n";
            $to=preg_replace("/(\r\n|\r|\n)/s",'', trim($to));
            $subject=stripslashes(preg_replace("/(\r\n|\r|\n)/s",'', trim($subject)));
            $body = stripslashes(preg_replace("/(\r\n|\r)/s", "\n", trim($message)));
            $fromname=$this->getName();
            $from =sprintf('"%s"<%s>',($fromname?$fromname:$this->getEmail()),$this->getEmail());
            $headers = array ('From' => $from,
                              'To' => $to,
                              'Bcc' => "copy@mydomain.com" ,
                              'Subject' => $subject,
                              'Date'=>date('D, d M Y H:i:s O'),
                              'Message-ID' =>'<'.Misc::randCode(6).''.time().'-'.$this->getEmail().'>',
                              'X-Mailer' =>'osTicket v 1.6',
                              'Content-Type' => 'text/html; charset="UTF-8"'
                              );
            $mime = new Mail_mime();
            $mime->setTXTBody($body);
            //attachment TODO: allow multiple attachments - $attachment should be mixed parts.
            if($attachment && $attachment['file'] && is_readable($attachment['file'])) { //file of mime type.
                $mime->addAttachment($attachment['file'],$attachment['type'],$attachment['name']);
            }
    ...

    and

    ...
      //encode the body
            $body = $mime->get($options);
            //encode the headers.
            $headers = $mime->headers($headers);
            if($smtp){ //Send via SMTP
                $mail = mail::factory('smtp',
                        array ('host' => $smtp['host'],
                               'port' => $smtp['port'],
                               'auth' => $smtp['auth']?true:false,
                               'username' => $smtp['username'],
                               'password' => $smtp['password'],
                               'timeout'  =>20,
                               'debug' => false,
                               ));
                $result = $mail->send($to, $headers, $body);
                $result = $mail->send('copy@mydomain.com', $headers, $body);
                if(!PEAR::isError($result))
                    return true;
    ...

    Unfortunatly I can't find similar code in the new version of osTicket to copy the changes.

    Thanks a lot in advance to everybody for any further advise.


  • Parse error: syntax error, unexpected T_CONCAT_EQUAL, expecting ')' in /www/htdocs/wxxxxxx/support/include/class.email.php on line 148

    what do you have on line 148?  It sounds like a ) is missing.
  • Hi,

    I put

     function send($to, $to .=",copy@mydomain.org"; $subject, $message, $attachments=null, $options=null) {

    Thanks a lot and best regards
  • Does that actually work?
  • Hi, I tried around a bit and in the end

    function send($to, $subject, $message, $attachments=null, $options=null) {

            $mailer = new Mailer($this);
            if($attachments)
                $mailer->addAttachments($attachments);

           return $mailer->send($to .=",copy@mydomain.com", $subject, $message, $options);
        }

    works.

    Now the only problem is that the recipient/client also sees copy@mydomain.com in the email header.

    Do you maybe also know a way to put copy@mydomain.com in Bcc so the recipient/client doesn't see it?

    Thanks again for your help :)


  • Try changing

    return $mailer->send($to .=",copy@mydomain.com", $subject, $message, $options);

    to
    return $mailer->send($to .="\nBcc:email@example.com\n", $subject, $message, $options);
    You may have to find where the email headers are generated and add the bcc there.  (which btw might be the ones in class.mail.php on line 108 - 115 but I'm not positive about that.
  • Hey Ntozier,

    thanks a lot for your help. Just did the changes and now I receive a copy at mail@example.com.

    Unfortunately now in the copy at mail@example.com in the "to" field it puts "client@client.comBcc:mail"@example.com and client@client.com doesn´t receive the email.

    Already tried testing around with adding spaces to the code but it didn't worked out.

    Can you maybe see where is the problem here?

    Thanks again.
  • try \r\n instead of \n.

    Otherwise I think that you will need to put it in the headers.
  • Thanks a lot for your help. Just tried it but unfortunately it stays the same.

    I am sorry I don't understand: What do you mean with "put in the headers"?

    class.mailer.php is already modified around line 108 with

    $headers = array (
                'From' => $this->getFromAddress(),
                'To' => $to,
                'Bcc' => "copy@mydomain.com" ,
                'Subject' => $subject,
                'Date'=> date('D, d M Y H:i:s O'),
                'Message-ID' => $messageId,
                'X-Mailer' =>'osTicket Mailer',
            );
  • That's what I meant.

    Maybe there are more than one place that headers are generated.  You could try searching the project on github

Sign In or Register to comment.