| Server IP : 13.235.167.51 / Your IP : 216.73.217.116 Web Server : Apache System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64 User : root ( 0) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/app.machinox.in/app/Helpers/ |
Upload File : |
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
use PDF;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
class EmailHelper
{
public static $disableEmailException = 1;
public static $disable_email_exception = 1;
public static function sendAccountActivationEmail($user, $link, $isTest = false)
{
try {
if ($user && $user->email) {
$to = Str::lower($user->email);
$subject = config("app.name") . ': Complete Account Activation';
$link = $link . $user->remember_token;
$res = Mail::send(
'mail.account-activation-template',
['user' => $user, 'link' => $link],
function ($message) use ($to, $subject) {
$message->to($to);
$message->subject($subject);
}
);
if ($isTest) {
dump($res);
}
}
} catch (TransportExceptionInterface $STe) {
if ($isTest) {
dd($STe);
}
if (self::$disableEmailException == 0) {
throw new \Exception(trans("messages.EMAIL_SERVICE_NOT_WORKS"));
}
} catch (\Exception $e) {
if ($isTest) {
dd($e);
}
if (self::$disableEmailException == 0) {
throw new \Exception($e->getMessage());
}
}
}
public static function sendPasswordResetOtp($user, $isTest = false)
{
// dd(Str::lower($user->email));
Log::info("sendPasswordResetOtp", (array)$user);
try {
if ($user && $user->email) {
$to = Str::lower($user->email);
$subject = 'Forgot Password Otp';
// $link = config('constants.RESET_PASSWORD_LINK_ORG') . $user->remember_token;
$res = Mail::send('emails.otp', ['user' => $user], function ($message) use ($to, $subject) {
$message->to($to);
$message->subject($subject);
});
if ($isTest) {
dump($res);
}
Log::info("Email Response", (array)$res);
}
} catch (TransportExceptionInterface $STe) {
Log::error("TransportExceptionInterface ",(array) $STe);
if ($isTest) {
dd($STe);
}
if (self::$disable_email_exception == 0) {
throw new \Exception("The mail service has encountered a problem. Please retry later or contact the site admin.");
}
} catch (\Exception $e) {
Log::error("Exception ",(array) $e);
if ($isTest) {
dd($e);
}
if (self::$disable_email_exception == 0) {
throw new \Exception($e->getMessage());
}
}
}
public static function sendOTP($user, $subject, $isTest = false)
{
try {
if ($user && $user->email) {
$to = Str::lower($user->email);
$res = Mail::send('mail.otp-template', ['user' => $user], function ($message) use ($to, $subject) {
$message->to($to);
$message->subject($subject);
});
if ($isTest) {
dump($res);
}
}
} catch (TransportExceptionInterface $STe) {
if ($isTest) {
dd($STe);
}
if (self::$disableEmailException == 0) {
throw new \Exception(trans("messages.EMAIL_SERVICE_NOT_WORKS"));
}
} catch (\Exception $e) {
if ($isTest) {
dd($e);
}
if (self::$disableEmailException == 0) {
throw new \Exception($e->getMessage());
}
}
}
public static function sendPasswordResetMail($user, $link, $isTest = false)
{
try {
if ($user && $user->email) {
$to = Str::lower($user->email);
$subject = 'Forgot Password';
$link = $link . $user->remember_token;
$res = Mail::send('mail.forgot-password-template', ['user' => $user, 'link' => $link], function ($message) use ($to, $subject) {
$message->to($to);
$message->subject($subject);
});
if ($isTest) {
dump($res);
}
}
} catch (TransportExceptionInterface $STe) {
if ($isTest) {
dd($STe);
}
if (self::$disableEmailException == 0) {
throw new \Exception(trans("messages.EMAIL_SERVICE_NOT_WORKS"));
}
} catch (\Exception $e) {
if ($isTest) {
dd($e);
}
if (self::$disableEmailException == 0) {
throw new \Exception($e->getMessage());
}
}
}
public static function sendAttachmentMail($subject, $user, $invoice, $file, $template, $isTest = false)
{
try {
set_time_limit(300);
if ($user && (!empty($user->email) || !empty($user->alt_email))) {
Log::info("Email Sent : " . $user->email);
Log::info("Email Sent : " . $user->alt_email ?? "No Found");
$email = $user->email;
if (empty($email) && isset($user->alt_email)) {
$email = $user->alt_email;
}
$user->subject = $subject;
$res = Mail::send($template, ['data' => $invoice], function ($message) use ($user, $file, $email) {
$message->to($email);
$message->subject($user->subject);
if ($file) {
$data = file_get_contents($file);
$message->attachData($data, basename($file));
}
});
if ($isTest) {
dump($res);
}
}
} catch (TransportExceptionInterface $STe) {
Log::info("Email Exception 1 : ", (array) $STe);
if ($isTest) {
dd($STe);
}
if (self::$disableEmailException == 0) {
throw new \Exception(trans("messages.EMAIL_SERVICE_NOT_WORKS"));
}
} catch (\Exception $e) {
Log::info("Email Exception 2 : ", (array) $e);
if ($isTest) {
dd($e);
}
if (self::$disableEmailException == 0) {
throw new \Exception($e->getMessage());
}
}
}
}