update 1.0.8.0
Commits for version update
This commit is contained in:
@@ -6,11 +6,12 @@ use App\Http\Controllers\Controller;
|
||||
use App\Model\Common\TemplateType;
|
||||
use App\Model\helpdesk\Agent\Department;
|
||||
use App\Model\helpdesk\Email\Emails;
|
||||
use App\Model\helpdesk\Settings\CommonSettings;
|
||||
use App\Model\helpdesk\Settings\Company;
|
||||
use App\Model\helpdesk\Settings\Email;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Exception;
|
||||
use Mail;
|
||||
|
||||
class PhpMailController extends Controller
|
||||
{
|
||||
@@ -21,447 +22,6 @@ class PhpMailController extends Controller
|
||||
return $emails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sending emails from the system.
|
||||
*
|
||||
* @return Mail
|
||||
*/
|
||||
public function sendmail($from, $to, $message, $template_variables)
|
||||
{
|
||||
// try {
|
||||
// dd($from);
|
||||
$from_address = $this->fetch_smtp_details($from);
|
||||
if ($from_address == null) {
|
||||
return $from_address;
|
||||
} else {
|
||||
// dd($from_address);
|
||||
$username = $from_address->email_address;
|
||||
$fromname = $from_address->email_name;
|
||||
$password = \Crypt::decrypt($from_address->password);
|
||||
$smtpsecure = $from_address->sending_encryption;
|
||||
$host = $from_address->sending_host;
|
||||
$port = $from_address->sending_port;
|
||||
$protocol = $from_address->sending_protocol;
|
||||
|
||||
if (isset($to['email'])) {
|
||||
$recipants = $to['email'];
|
||||
} else {
|
||||
$recipants = null;
|
||||
}
|
||||
if (isset($to['name'])) {
|
||||
$recipantname = $to['name'];
|
||||
} else {
|
||||
$recipantname = null;
|
||||
}
|
||||
if (isset($to['cc'])) {
|
||||
$cc = $to['cc'];
|
||||
} else {
|
||||
$cc = null;
|
||||
}
|
||||
if (isset($to['bc'])) {
|
||||
$bc = $to['bc'];
|
||||
} else {
|
||||
$bc = null;
|
||||
}
|
||||
// if (isset($message['subject'])) {
|
||||
// $subject = $message['subject'];
|
||||
// } else {
|
||||
// $subject = null;
|
||||
// }
|
||||
if (isset($message['body'])) {
|
||||
$content = $message['body'];
|
||||
} else {
|
||||
$content = null;
|
||||
}
|
||||
if (isset($message['scenario'])) {
|
||||
$template = $message['scenario'];
|
||||
} else {
|
||||
$template = null;
|
||||
}
|
||||
if (isset($message['attachments'])) {
|
||||
$attachment = $message['attachments'];
|
||||
} else {
|
||||
$attachment = null;
|
||||
}
|
||||
|
||||
// Inline Attachments
|
||||
if (isset($message['add_embedded_image'])) {
|
||||
$add_embedded_images = $message['add_embedded_image'];
|
||||
} else {
|
||||
$add_embedded_images = null;
|
||||
}
|
||||
|
||||
// template variables
|
||||
if (Auth::user()) {
|
||||
$agent = Auth::user()->user_name;
|
||||
} else {
|
||||
$agent = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_agent_name'])) {
|
||||
$ticket_agent_name = $template_variables['ticket_agent_name'];
|
||||
} else {
|
||||
$ticket_agent_name = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_number'])) {
|
||||
$ticket_number = $template_variables['ticket_number'];
|
||||
} else {
|
||||
$ticket_number = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_client_name'])) {
|
||||
$ticket_client_name = $template_variables['ticket_client_name'];
|
||||
} else {
|
||||
$ticket_client_name = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_client_email'])) {
|
||||
$ticket_client_email = $template_variables['ticket_client_email'];
|
||||
} else {
|
||||
$ticket_client_email = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_body'])) {
|
||||
$ticket_body = $template_variables['ticket_body'];
|
||||
} else {
|
||||
$ticket_body = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_assigner'])) {
|
||||
$ticket_assigner = $template_variables['ticket_assigner'];
|
||||
} else {
|
||||
$ticket_assigner = null;
|
||||
}
|
||||
if (isset($template_variables['ticket_link_with_number'])) {
|
||||
$ticket_link_with_number = $template_variables['ticket_link_with_number'];
|
||||
} else {
|
||||
$ticket_link_with_number = null;
|
||||
}
|
||||
if (isset($template_variables['system_from'])) {
|
||||
$system_from = $template_variables['system_from'];
|
||||
} else {
|
||||
$system_from = $this->company();
|
||||
}
|
||||
if (isset($template_variables['system_link'])) {
|
||||
$system_link = $template_variables['system_link'];
|
||||
} else {
|
||||
$system_link = url('/');
|
||||
}
|
||||
if (isset($template_variables['system_error'])) {
|
||||
$system_error = $template_variables['system_error'];
|
||||
} else {
|
||||
$system_error = null;
|
||||
}
|
||||
if (isset($template_variables['agent_sign'])) {
|
||||
$agent_sign = $template_variables['agent_sign'];
|
||||
} else {
|
||||
$agent_sign = null;
|
||||
}
|
||||
if (isset($template_variables['department_sign'])) {
|
||||
$department_sign = $template_variables['department_sign'];
|
||||
} else {
|
||||
$department_sign = null;
|
||||
}
|
||||
if (isset($template_variables['password_reset_link'])) {
|
||||
$password_reset_link = $template_variables['password_reset_link'];
|
||||
} else {
|
||||
$password_reset_link = null;
|
||||
}
|
||||
if (isset($template_variables['user_password'])) {
|
||||
$user_password = $template_variables['user_password'];
|
||||
} else {
|
||||
$user_password = null;
|
||||
}
|
||||
if (isset($template_variables['email_address'])) {
|
||||
$email_address = $template_variables['email_address'];
|
||||
} else {
|
||||
$email_address = null;
|
||||
}
|
||||
if (isset($template_variables['user'])) {
|
||||
$user = $template_variables['user'];
|
||||
} else {
|
||||
$user = null;
|
||||
}
|
||||
|
||||
// $system_link = url('/');
|
||||
|
||||
// $system_from = $this->company();
|
||||
|
||||
$mail = new \PHPMailer();
|
||||
|
||||
$status = \DB::table('settings_email')->first();
|
||||
|
||||
$path2 = \Config::get('view.paths');
|
||||
|
||||
// $directory = $path2[0].DIRECTORY_SEPARATOR.'emails'.DIRECTORY_SEPARATOR.$status->template.DIRECTORY_SEPARATOR;
|
||||
//
|
||||
// $handle = fopen($directory.$template.'.blade.php', 'r');
|
||||
// $contents = fread($handle, filesize($directory.$template.'.blade.php'));
|
||||
// fclose($handle);
|
||||
|
||||
$template = TemplateType::where('name', '=', $template)->first();
|
||||
|
||||
$set = \App\Model\Common\TemplateSet::where('name', '=', $status->template)->first();
|
||||
|
||||
if (isset($set['id'])) {
|
||||
$template_data = \App\Model\Common\Template::where('set_id', '=', $set->id)->where('type', '=', $template->id)->first();
|
||||
$contents = $template_data->message;
|
||||
if ($template_data->variable == 1) {
|
||||
if ($template_data->subject) {
|
||||
$subject = $template_data->subject;
|
||||
if ($ticket_number != null) {
|
||||
$subject = $subject.' [#'.$ticket_number.']';
|
||||
}
|
||||
} else {
|
||||
$subject = $message['subject'];
|
||||
}
|
||||
} else {
|
||||
$subject = $message['subject'];
|
||||
}
|
||||
} else {
|
||||
$contents = null;
|
||||
$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!!}'];
|
||||
|
||||
$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];
|
||||
|
||||
// dd($variables,$data,$contents);
|
||||
// $messagebody = str_replace($variables, $data, $contents);
|
||||
|
||||
foreach ($variables as $key => $variable) {
|
||||
$messagebody = str_replace($variables[$key], $data[$key], $contents);
|
||||
// dd($messagebody);
|
||||
|
||||
$contents = $messagebody;
|
||||
}
|
||||
|
||||
// dd($messagebody);
|
||||
//$mail->SMTPDebug = 3; // Enable verbose debug output
|
||||
if ($protocol == 'smtp') {
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = $host; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = $username; // SMTP username
|
||||
$mail->Password = $password; // SMTP password
|
||||
$mail->SMTPSecure = $smtpsecure; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = $port; // TCP port to connect to
|
||||
$mail->setFrom($username, $fromname);
|
||||
} elseif ($protocol == 'mail') {
|
||||
$mail->IsSendmail(); // telling the class to use SendMail transport
|
||||
if ($username == $fromname) {
|
||||
$mail->setFrom($username);
|
||||
} else {
|
||||
$mail->setFrom($username, $fromname);
|
||||
}
|
||||
}
|
||||
$mail->addAddress($recipants); // Add a recipient
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
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;
|
||||
$mail->addCC($collab_email);
|
||||
}
|
||||
}
|
||||
|
||||
if ($attachment != null) {
|
||||
$size = count($message['attachments']);
|
||||
$attach = $message['attachments'];
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$file_path = $attach[$i]->getRealPath();
|
||||
$file_name = $attach[$i]->getClientOriginalName();
|
||||
$mail->addAttachment($file_path, $file_name);
|
||||
}
|
||||
}
|
||||
|
||||
// inline images embedded as attachments
|
||||
if ($add_embedded_images != null) {
|
||||
// dd($add_embedded_images);
|
||||
foreach ($add_embedded_images as $add_embedded_image) {
|
||||
if (isset($add_embedded_image->id)) {
|
||||
$cid = $add_embedded_image->id;
|
||||
} else {
|
||||
$cid = null;
|
||||
}
|
||||
if (isset($add_embedded_image->name)) {
|
||||
$file_name = $add_embedded_image->name;
|
||||
} else {
|
||||
$file_name = null;
|
||||
}
|
||||
if (isset($add_embedded_image->filePath)) {
|
||||
$file_path = $add_embedded_image->filePath;
|
||||
} else {
|
||||
$file_path = null;
|
||||
}
|
||||
if (isset($add_embedded_image->disposition)) {
|
||||
if ($add_embedded_image->disposition == 'INLINE') {
|
||||
$mail->AddEmbeddedImage($file_path, $cid, $file_name);
|
||||
} else {
|
||||
$mail->addAttachment($file_path, $file_name);
|
||||
}
|
||||
} else {
|
||||
$file_path = $add_embedded_image->getRealPath();
|
||||
$file_name = $add_embedded_image->getClientOriginalName();
|
||||
$mail->addAttachment($file_path, $file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mail->CharSet = 'utf8';
|
||||
$mail->Subject = $subject;
|
||||
if ($template == 'ticket-reply-agent') {
|
||||
$line = '---Reply above this line--- <br/><br/>';
|
||||
$body = $line.$messagebody;
|
||||
} else {
|
||||
$body = $messagebody;
|
||||
}
|
||||
$rtl = CommonSettings::where('option_name', '=', 'enable_rtl')->first();
|
||||
if ($rtl->option_value == 1) {
|
||||
$mail->ContentType = 'text/html';
|
||||
$body = '<html dir="rtl" xml:lang="ar" lang="ar"><head></head><body dir="rtl">'.$body.'</body></html>';
|
||||
} else {
|
||||
}
|
||||
$mail->Body = nl2br($body);
|
||||
|
||||
if (!$mail->send()) {
|
||||
return;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sending emails from the system.
|
||||
*
|
||||
* @return MailNotification
|
||||
*/
|
||||
public function sendEmail($from, $to, $message)
|
||||
{
|
||||
try {
|
||||
$from_address = $this->fetch_smtp_details($from);
|
||||
if ($from_address == null) {
|
||||
return $from_address;
|
||||
} else {
|
||||
$username = $from_address->email_address;
|
||||
$fromname = $from_address->email_name;
|
||||
$password = \Crypt::decrypt($from_address->password);
|
||||
$smtpsecure = $from_address->sending_encryption;
|
||||
$host = $from_address->sending_host;
|
||||
$port = $from_address->sending_port;
|
||||
$protocol = $from_address->sending_protocol;
|
||||
|
||||
if (isset($to['email'])) {
|
||||
$recipants = $to['email'];
|
||||
} else {
|
||||
$recipants = null;
|
||||
}
|
||||
if (isset($to['name'])) {
|
||||
$recipantname = $to['name'];
|
||||
} else {
|
||||
$recipantname = null;
|
||||
}
|
||||
if (isset($to['cc'])) {
|
||||
$cc = $to['cc'];
|
||||
} else {
|
||||
$cc = null;
|
||||
}
|
||||
if (isset($to['bc'])) {
|
||||
$bc = $to['bc'];
|
||||
} else {
|
||||
$bc = null;
|
||||
}
|
||||
if (isset($message['subject'])) {
|
||||
$subject = $message['subject'];
|
||||
} else {
|
||||
$subject = null;
|
||||
}
|
||||
if (isset($message['body'])) {
|
||||
$content = $message['body'];
|
||||
} else {
|
||||
$content = null;
|
||||
}
|
||||
if (isset($message['scenario'])) {
|
||||
$template = $message['scenario'];
|
||||
} else {
|
||||
$template = null;
|
||||
}
|
||||
if (isset($message['attachments'])) {
|
||||
$attachment = $message['attachments'];
|
||||
} else {
|
||||
$attachment = null;
|
||||
}
|
||||
|
||||
// template variables
|
||||
if (Auth::user()) {
|
||||
$agent = Auth::user()->user_name;
|
||||
} else {
|
||||
$agent = null;
|
||||
}
|
||||
|
||||
$system_link = url('/');
|
||||
|
||||
$system_from = $this->company();
|
||||
|
||||
$mail = new \PHPMailer();
|
||||
|
||||
$status = \DB::table('settings_email')->first();
|
||||
|
||||
// dd($messagebody);
|
||||
//$mail->SMTPDebug = 3; // Enable verbose debug output
|
||||
if ($protocol == 'smtp') {
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = $host; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = $username; // SMTP username
|
||||
$mail->Password = $password; // SMTP password
|
||||
$mail->SMTPSecure = $smtpsecure; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = $port; // TCP port to connect to
|
||||
$mail->setFrom($username, $fromname);
|
||||
} elseif ($protocol == 'mail') {
|
||||
$mail->IsSendmail(); // telling the class to use SendMail transport
|
||||
if ($username == $fromname) {
|
||||
$mail->setFrom($username);
|
||||
} else {
|
||||
$mail->setFrom($username, $fromname);
|
||||
}
|
||||
}
|
||||
$mail->addAddress($recipants); // Add a recipient
|
||||
// Name is optional
|
||||
// $mail->addReplyTo('sada059@gmail.com', 'Information');
|
||||
// Optional name
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
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;
|
||||
$mail->addCC($collab_email);
|
||||
}
|
||||
}
|
||||
if ($attachment != null) {
|
||||
$size = count($message['attachments']);
|
||||
$attach = $message['attachments'];
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$file_path = $attach[$i]->getRealPath();
|
||||
$file_name = $attach[$i]->getClientOriginalName();
|
||||
$mail->addAttachment($file_path, $file_name);
|
||||
}
|
||||
}
|
||||
$mail->CharSet = 'utf8';
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $content;
|
||||
if (!$mail->send()) {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
if ($e instanceof ErrorException) {
|
||||
return \Lang::get('lang.outgoing_email_failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetching comapny name to send mail.
|
||||
*
|
||||
@@ -501,4 +61,246 @@ class PhpMailController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function sendEmail($from, $to, $message, $template_variables)
|
||||
{
|
||||
$from_address = $this->fetch_smtp_details($from);
|
||||
if ($from_address == null) {
|
||||
throw new Exception('Invalid Email Configuration');
|
||||
}
|
||||
|
||||
$this->setMailConfig($from_address);
|
||||
|
||||
$recipants = $this->checkElement('email', $to);
|
||||
$recipantname = $this->checkElement('name', $to);
|
||||
$cc = $this->checkElement('cc', $to);
|
||||
$bc = $this->checkElement('bc', $to);
|
||||
$subject = $this->checkElement('subject', $message);
|
||||
$content = $this->checkElement('body', $message);
|
||||
$template_type = $this->checkElement('scenario', $message);
|
||||
$attachment = $this->checkElement('attachments', $message);
|
||||
|
||||
$agent = null;
|
||||
// template variables
|
||||
if (Auth::user()) {
|
||||
$agent = Auth::user()->user_name;
|
||||
}
|
||||
$ticket_agent_name = $this->checkElement('ticket_agent_name', $template_variables);
|
||||
$ticket_number = $this->checkElement('ticket_number', $template_variables);
|
||||
$ticket_client_name = $this->checkElement('ticket_client_name', $template_variables);
|
||||
$ticket_client_email = $this->checkElement('ticket_client_email', $template_variables);
|
||||
$ticket_body = $this->checkElement('ticket_body', $template_variables);
|
||||
$ticket_assigner = $this->checkElement('ticket_assigner', $template_variables);
|
||||
$ticket_link_with_number = $this->checkElement('ticket_link_with_number', $template_variables);
|
||||
|
||||
$system_from = $this->checkElement('system_from', $template_variables);
|
||||
if ($system_from === '') {
|
||||
$system_from = $this->company();
|
||||
}
|
||||
$system_link = $this->checkElement('system_link', $template_variables);
|
||||
if ($system_link === '') {
|
||||
$system_link = url('/');
|
||||
}
|
||||
$system_error = $this->checkElement('system_error', $template_variables);
|
||||
$agent_sign = $this->checkElement('agent_sign', $template_variables);
|
||||
$department_sign = $this->checkElement('department_sign', $template_variables);
|
||||
$password_reset_link = $this->checkElement('password_reset_link', $template_variables);
|
||||
$user_password = $this->checkElement('user_password', $template_variables);
|
||||
|
||||
$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();
|
||||
|
||||
$set = \App\Model\Common\TemplateSet::where('name', '=', $status->template)->first();
|
||||
if ($template) {
|
||||
if (isset($set['id'])) {
|
||||
$template_data = \App\Model\Common\Template::where('set_id', '=', $set->id)->where('type', '=', $template->id)->first();
|
||||
$contents = $template_data->message;
|
||||
if ($template_data->variable == 1) {
|
||||
if ($template_data->subject) {
|
||||
$subject = $template_data->subject;
|
||||
if ($ticket_number != null) {
|
||||
$subject = $subject.' [#'.$ticket_number.']';
|
||||
}
|
||||
} else {
|
||||
$subject = $message['subject'];
|
||||
}
|
||||
} else {
|
||||
$subject = $message['subject'];
|
||||
}
|
||||
} else {
|
||||
$contents = null;
|
||||
$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!!}'];
|
||||
|
||||
$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];
|
||||
|
||||
foreach ($variables as $key => $variable) {
|
||||
$messagebody = str_replace($variables[$key], $data[$key], $contents);
|
||||
$contents = $messagebody;
|
||||
}
|
||||
|
||||
|
||||
if ($template_type == 'ticket-reply-agent') {
|
||||
$line = '---Reply above this line--- <br/><br/>';
|
||||
$content = $line.$messagebody;
|
||||
} else {
|
||||
$content = $messagebody;
|
||||
}
|
||||
}
|
||||
$send = $this->laravelMail($recipants, $recipantname, $subject, $content, $cc, $attachment);
|
||||
|
||||
return $send;
|
||||
}
|
||||
|
||||
public function setMailConfig($from_address)
|
||||
{
|
||||
$username = $from_address->email_address;
|
||||
$fromname = $from_address->email_name;
|
||||
$password = $from_address->password;
|
||||
$smtpsecure = $from_address->sending_encryption;
|
||||
$host = $from_address->sending_host;
|
||||
$port = $from_address->sending_port;
|
||||
$protocol = $from_address->sending_protocol;
|
||||
$this->setServices($from_address->id, $protocol);
|
||||
if($protocol=='mail'){
|
||||
$username = "";
|
||||
$fromname="";
|
||||
$host="";
|
||||
$smtpsecure ="";
|
||||
$port="";
|
||||
}
|
||||
$configs = [
|
||||
'username' => $username,
|
||||
'from' => ['address' => $username, 'name' => $fromname],
|
||||
'password' => $password,
|
||||
'encryption' => $smtpsecure,
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
'driver' => $protocol,
|
||||
];
|
||||
foreach ($configs as $key => $config) {
|
||||
if (is_array($config)) {
|
||||
foreach ($config as $from) {
|
||||
\Config::set('mail.'.$key, $config);
|
||||
}
|
||||
} else {
|
||||
\Config::set('mail.'.$key, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = '';
|
||||
if (is_array($array)) {
|
||||
if (array_key_exists($element, $array)) {
|
||||
$value = $array[$element];
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// $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'];
|
||||
}
|
||||
$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()
|
||||
{
|
||||
$short = 'database';
|
||||
$field = [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'expire' => 60,
|
||||
];
|
||||
$queue = new \App\Model\MailJob\QueueService();
|
||||
$active_queue = $queue->where('status', 1)->first();
|
||||
if ($active_queue) {
|
||||
$short = $active_queue->short_name;
|
||||
$fields = new \App\Model\MailJob\FaveoQueue();
|
||||
$field = $fields->where('service_id', $active_queue->id)->lists('value', 'key')->toArray();
|
||||
}
|
||||
$this->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)
|
||||
{
|
||||
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