PHP Classes

File: apps/helpers/mail_sender.php

Recommend this page to a friend!
  Packages of fathurrahman   mnTemplate   apps/helpers/mail_sender.php   Download  
File: apps/helpers/mail_sender.php
Role: Example script
Content type: text/plain
Description: Example script
Class: mnTemplate
Route HTTP requests to callback functions
Author: By
Last change:
Date: 3 years ago
Size: 1,461 bytes
 

 

Contents

Class file image Download
<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function sendemail($email_tujuan, $pesan = null, $subject = null, $nama_pengirim = 'Keuangan BQN', $email_pengirim = 'kamscode@kamscode.tech')
{
    require DEPENDENCIES_PATH . convert_path('phpmailer/phpmailer/src/Exception.php');
    require DEPENDENCIES_PATH . convert_path('phpmailer/phpmailer/src/PHPMailer.php');
    require DEPENDENCIES_PATH . convert_path('phpmailer/phpmailer/src/SMTP.php');
    $mail = new PHPMailer(TRUE);

    try {
        /* Set the mail sender. */
        $mail->IsSMTP();
        $mail->Host = "mail.kamscode.tech";

        // optional
        // used only when SMTP requires authentication  
        $mail->SMTPAuth = true;
        $mail->Username = 'kamscode';
        $mail->Password = '3bS9Fn2g8n';
        $email_tujuan = strtolower($email_tujuan);
        $mail->setFrom($email_pengirim, $nama_pengirim);

        /* Add a recipient. */
        $mail->addAddress($email_tujuan);

        /* Set the subject. */
        $mail->Subject = $subject;

        /* Set the mail message body. */
        $mail->Body = $pesan;

        $mail->send();
        return ['message' => 'Berhasil mengirim email', 'sts' => true];
    } catch (Exception $e) {
        return ['message' => $e->errorMessage(), 'sts' => false];
        echo $e->errorMessage();
    } catch (\Exception $e) {
        return ['message' => $e->getMessage(), 'sts' => false];
    }
}