Updates
This commit is contained in:
@@ -10,16 +10,14 @@ use App\Model\helpdesk\Settings\Company;
|
||||
use App\Model\helpdesk\Settings\Email;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Mail;
|
||||
use Exception;
|
||||
use Lang;
|
||||
use Mail;
|
||||
|
||||
class PhpMailController extends Controller
|
||||
{
|
||||
public function fetch_smtp_details($id)
|
||||
{
|
||||
class PhpMailController extends Controller {
|
||||
|
||||
public function fetch_smtp_details($id) {
|
||||
$emails = Emails::where('id', '=', $id)->first();
|
||||
|
||||
return $emails;
|
||||
}
|
||||
|
||||
@@ -28,8 +26,7 @@ class PhpMailController extends Controller
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
public function company() {
|
||||
$company = Company::Where('id', '=', '1')->first();
|
||||
if ($company->company_name == null) {
|
||||
$company = 'Support Center';
|
||||
@@ -48,32 +45,27 @@ class PhpMailController extends Controller
|
||||
*
|
||||
* @return type integer
|
||||
*/
|
||||
public function mailfrom($reg, $dept_id)
|
||||
{
|
||||
$email = Email::where('id', '=', '1')->first();
|
||||
if ($reg == 1) {
|
||||
return $email->sys_email;
|
||||
} elseif ($dept_id > 0) {
|
||||
$department = Department::where('id', '=', $dept_id)->first();
|
||||
if ($department->outgoing_email) {
|
||||
return $department->outgoing_email;
|
||||
} else {
|
||||
return $email->sys_email;
|
||||
}
|
||||
public function mailfrom($reg, $dept_id) {
|
||||
$email_id = "";
|
||||
$emails = Emails::where('department', '=', $dept_id)->first();
|
||||
|
||||
$email = Email::find(1);
|
||||
if ($emails && $emails->sending_status) {
|
||||
$email_id = $emails->id;
|
||||
} else {
|
||||
$email_id = $email->sys_email;
|
||||
}
|
||||
return $email_id;
|
||||
}
|
||||
|
||||
public function sendmail($from, $to, $message, $template_variables)
|
||||
{
|
||||
public function sendmail($from, $to, $message, $template_variables) {
|
||||
$this->setQueue();
|
||||
$job = new \App\Jobs\SendEmail($from, $to, $message, $template_variables);
|
||||
$dispatch = $this->dispatch($job);
|
||||
|
||||
return $dispatch;
|
||||
$this->dispatch($job);
|
||||
}
|
||||
|
||||
public function sendEmail($from, $to, $message, $template_variables)
|
||||
{
|
||||
public function sendEmail($from, $to, $message, $template_variables) {
|
||||
|
||||
$from_address = $this->fetch_smtp_details($from);
|
||||
if ($from_address == null) {
|
||||
throw new Exception(Lang::get('lang.system-email-not-configured'));
|
||||
@@ -104,11 +96,11 @@ class PhpMailController extends Controller
|
||||
$ticket_link_with_number = $this->checkElement('ticket_link_with_number', $template_variables);
|
||||
|
||||
$system_from = $this->checkElement('system_from', $template_variables);
|
||||
if ($system_from === '') {
|
||||
if ($system_from === "") {
|
||||
$system_from = $this->company();
|
||||
}
|
||||
$system_link = $this->checkElement('system_link', $template_variables);
|
||||
if ($system_link === '') {
|
||||
if ($system_link === "") {
|
||||
$system_link = \Config::get('app.url');
|
||||
}
|
||||
$ticket_link = $this->checkElement('ticket_link', $template_variables);
|
||||
@@ -121,6 +113,7 @@ class PhpMailController extends Controller
|
||||
$email_address = $this->checkElement('email_address', $template_variables);
|
||||
$user = $this->checkElement('user', $template_variables);
|
||||
|
||||
|
||||
$status = \DB::table('settings_email')->first();
|
||||
|
||||
$template = TemplateType::where('name', '=', $template_type)->first();
|
||||
@@ -134,7 +127,7 @@ class PhpMailController extends Controller
|
||||
if ($template_data->subject) {
|
||||
$subject = $template_data->subject;
|
||||
if ($ticket_number != null) {
|
||||
$subject = $subject.' [#'.$ticket_number.']';
|
||||
$subject = $subject . ' [#' . $ticket_number . ']';
|
||||
}
|
||||
} else {
|
||||
$subject = $message['subject'];
|
||||
@@ -147,6 +140,7 @@ class PhpMailController extends Controller
|
||||
$subject = null;
|
||||
}
|
||||
|
||||
|
||||
$variables = ['{!!$user!!}', '{!!$agent!!}', '{!!$ticket_number!!}', '{!!$content!!}', '{!!$from!!}', '{!!$ticket_agent_name!!}', '{!!$ticket_client_name!!}', '{!!$ticket_client_email!!}', '{!!$ticket_body!!}', '{!!$ticket_assigner!!}', '{!!$ticket_link_with_number!!}', '{!!$system_error!!}', '{!!$agent_sign!!}', '{!!$department_sign!!}', '{!!$password_reset_link!!}', '{!!$email_address!!}', '{!!$user_password!!}', '{!!$system_from!!}', '{!!$system_link!!}', '{!!$ticket_link!!}'];
|
||||
|
||||
$data = [$user, $agent, $ticket_number, $content, $from, $ticket_agent_name, $ticket_client_name, $ticket_client_email, $ticket_body, $ticket_assigner, $ticket_link_with_number, $system_error, $agent_sign, $department_sign, $password_reset_link, $email_address, $user_password, $system_from, $system_link, $ticket_link];
|
||||
@@ -156,20 +150,20 @@ class PhpMailController extends Controller
|
||||
$contents = $messagebody;
|
||||
}
|
||||
|
||||
|
||||
if ($template_type == 'ticket-reply-agent') {
|
||||
$line = '---Reply above this line--- <br/><br/>';
|
||||
$content = $line.$messagebody;
|
||||
$content = $line . $messagebody;
|
||||
} else {
|
||||
$content = $messagebody;
|
||||
}
|
||||
}
|
||||
$send = $this->laravelMail($recipants, $recipantname, $subject, $content, $cc, $attachment);
|
||||
|
||||
return $send;
|
||||
}
|
||||
|
||||
public function setMailConfig($from_address)
|
||||
{
|
||||
public function setMailConfig($from_address) {
|
||||
|
||||
$username = $from_address->email_address;
|
||||
$fromname = $from_address->email_name;
|
||||
$password = $from_address->password;
|
||||
@@ -186,94 +180,88 @@ class PhpMailController extends Controller
|
||||
$port = '';
|
||||
}
|
||||
$configs = [
|
||||
'username' => $username,
|
||||
'from' => ['address' => $username, 'name' => $fromname],
|
||||
'password' => $password,
|
||||
'username' => $username,
|
||||
'from' => ['address' => $username, 'name' => $fromname,],
|
||||
'password' => $password,
|
||||
'encryption' => $smtpsecure,
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
'driver' => $protocol,
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
'driver' => $protocol,
|
||||
];
|
||||
foreach ($configs as $key => $config) {
|
||||
if (is_array($config)) {
|
||||
foreach ($config as $from) {
|
||||
\Config::set('mail.'.$key, $config);
|
||||
\Config::set('mail.' . $key, $config);
|
||||
}
|
||||
} else {
|
||||
\Config::set('mail.'.$key, $config);
|
||||
\Config::set('mail.' . $key, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setServices($emailid, $protocol)
|
||||
{
|
||||
public function setServices($emailid, $protocol) {
|
||||
$service = new \App\Model\MailJob\FaveoMail();
|
||||
$services = $service->where('email_id', $emailid)->lists('value', 'key')->toArray();
|
||||
$controller = new \App\Http\Controllers\Admin\helpdesk\EmailsController();
|
||||
$controller->setServiceConfig($protocol, $services);
|
||||
}
|
||||
|
||||
public function checkElement($element, $array)
|
||||
{
|
||||
$value = '';
|
||||
public function checkElement($element, $array) {
|
||||
$value = "";
|
||||
if (is_array($array)) {
|
||||
if (array_key_exists($element, $array)) {
|
||||
if (key_exists($element, $array)) {
|
||||
$value = $array[$element];
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function laravelMail($to, $toname, $subject, $data, $cc, $attach)
|
||||
{
|
||||
public function laravelMail($to, $toname, $subject, $data, $cc, $attach) {
|
||||
//dd($to, $toname, $subject, $data, $cc, $attach);
|
||||
//dd(\Config::get('mail'));
|
||||
//dd($attach);
|
||||
$mail = Mail::send('emails.mail', ['data' => $data], function ($m) use ($to, $subject, $toname, $cc, $attach) {
|
||||
$m->to($to, $toname)->subject($subject);
|
||||
$m->to($to, $toname)->subject($subject);
|
||||
|
||||
if ($cc != null) {
|
||||
foreach ($cc as $collaborator) {
|
||||
//mail to collaborators
|
||||
if ($cc != null) {
|
||||
foreach ($cc as $collaborator) {
|
||||
//mail to collaborators
|
||||
$collab_user_id = $collaborator->user_id;
|
||||
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
|
||||
$collab_email = $user_id_collab->email;
|
||||
$m->cc($collab_email);
|
||||
}
|
||||
}
|
||||
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
|
||||
$collab_email = $user_id_collab->email;
|
||||
$m->cc($collab_email);
|
||||
}
|
||||
}
|
||||
|
||||
// $mail->addBCC($bc);
|
||||
$size = count($attach);
|
||||
if ($size > 0) {
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
if (is_array($attach) && array_key_exists($i, $attach)) {
|
||||
$mode = 'normal';
|
||||
if (is_array($attach[$i]) && array_key_exists('mode', $attach[$i])) {
|
||||
$mode = $attach[$i]['mode'];
|
||||
if ($size > 0) {
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
if (is_array($attach) && array_key_exists($i, $attach)) {
|
||||
$mode = 'normal';
|
||||
if (is_array($attach[$i]) && array_key_exists('mode', $attach[$i])) {
|
||||
$mode = $attach[$i]['mode'];
|
||||
}
|
||||
$file = $attach[$i]['file_path'];
|
||||
$name = $attach[$i]['file_name'];
|
||||
$mime = $attach[$i]['mime'];
|
||||
$this->attachmentMode($m, $file, $name, $mime, $mode);
|
||||
}
|
||||
}
|
||||
$file = $attach[$i]['file_path'];
|
||||
$name = $attach[$i]['file_name'];
|
||||
$mime = $attach[$i]['mime'];
|
||||
$this->attachmentMode($m, $file, $name, $mime, $mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if (is_object($mail) || (is_object($mail) && $mail->getStatusCode() == 200)) {
|
||||
$mail = 1;
|
||||
}
|
||||
|
||||
return $mail;
|
||||
}
|
||||
|
||||
public function setQueue()
|
||||
{
|
||||
public function setQueue() {
|
||||
$short = 'database';
|
||||
$field = [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'expire' => 60,
|
||||
];
|
||||
$queue = new \App\Model\MailJob\QueueService();
|
||||
@@ -286,20 +274,18 @@ class PhpMailController extends Controller
|
||||
$this->setQueueConfig($short, $field);
|
||||
}
|
||||
|
||||
public function setQueueConfig($short, $field)
|
||||
{
|
||||
public function setQueueConfig($short, $field) {
|
||||
\Config::set('queue.default', $short);
|
||||
foreach ($field as $key => $value) {
|
||||
\Config::set("queue.connections.$short.$key", $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function attachmentMode($message, $file, $name, $mime, $mode)
|
||||
{
|
||||
public function attachmentMode($message, $file, $name, $mime, $mode) {
|
||||
if ($mode == 'data') {
|
||||
return $message->attachData(base64_decode($file, true), $name, ['mime' => $mime]);
|
||||
}
|
||||
|
||||
return $message->attach($file, ['as' => $name, 'mime' => $mime]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user