-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseMail.php
65 lines (51 loc) · 2.68 KB
/
BaseMail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Mail;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
//Create an instance; passing `true` enables exceptions
class BaseMail {
public $mails;
public function __construct()
{
$this->mails = new PHPMailer(true);
}
public function sendMail($Email, $Name, $Subject, $Body, $AltBody)
{
try {
//Server settings
$this->mails->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$this->mails->isSMTP(); //Send using SMTP
$this->mails->Host = MAIL_HOST; //Set the SMTP server to send through
$this->mails->SMTPAuth = true; //Enable SMTP authentication
$this->mails->Username = MAIL_USERNAME; //SMTP username
$this->mails->Password = MAIL_PASSWORD; //SMTP password
$this->mails->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$this->mails->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
$this->mails->SMTPDebug = MAIL_DEBUG;
//Recipients
$this->mails->setFrom(MAIL_FROMEMAIL, MAIL_FROMNAME);
$this->mails->addAddress($Email, $Name); //Add a recipient
//$this->mails->addAddress('[email protected]'); //Name is optional
//$this->mails->addReplyTo('[email protected]', 'Information');
//$this->mails->addCC('[email protected]');
//$this->mails->addBCC('[email protected]');
//Attachments
//$this->mails->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
//$this->mails->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
$this->mails->setLanguage( 'id' , 'vendor/phpmailer/phpmailer/language/phpmailer.lang-id.php' );
//Content
$this->mails->isHTML(true); //Set email format to HTML
$this->mails->Subject = $Subject;
$this->mails->Body = $Body;
$this->mails->AltBody = $AltBody;
$this->mails->send();
return 'OK';
} catch (Exception $e) {
return "FALSE";
//return "Message could not be sent. Mailer Error: {$this->mails->ErrorInfo}";
}
}
}