Update notifikasi send email
This commit is contained in:
@@ -6,6 +6,8 @@ use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Helper
|
||||
{
|
||||
@@ -244,14 +246,52 @@ class Helper
|
||||
return $convertedDate;
|
||||
}
|
||||
|
||||
public static function sendNotification()
|
||||
public static function insertNotification($data = array())
|
||||
{
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
DB::table('notifications')->insert($data);
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendEmail()
|
||||
public static function sendEmail($data = array())
|
||||
{
|
||||
// Buat instance PHPMailer
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
// Server settings
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'smtp.gmail.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = env('EMAIL');
|
||||
$mail->Password = env('PW_EMAIL');
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = "ssl";
|
||||
|
||||
// Penerima email
|
||||
$mail->setFrom(env('EMAIL'), env('NAME_EMAIL'));
|
||||
$mail->addAddress($data['email'], $data['name']);
|
||||
|
||||
// Konten email
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $data['subject'];
|
||||
$mail->Body = $data['body'];
|
||||
|
||||
// Kirim email
|
||||
$mail->send();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
//var_dump($mail->ErrorInfo);die();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user