-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail.php
53 lines (47 loc) · 2.23 KB
/
mail.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
<?php
declare(strict_types=1);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once('vendor/autoload.php');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
function domail( $to,$toname, $subject, $body, $attachment = '', $cc = '', $bcc = '' ) {
$mail = new PHPMailer(true);
//Server settings
try {
$mail->SMTPDebug = 0; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = $_ENV['SMTP_HOST']; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = $_ENV['SMTP_USER']; //SMTP username
$mail->Password = $_ENV['SMTP_PASS']; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = $_ENV['SMTP_PORT']; //Set the SMTP port
$mail->addCustomHeader('MIME-Version', '1.0');
$mail->addCustomHeader('DATE', date('r'));
//Recipients
$mail->addAddress( $to, $toname ); // Add a recipient
if ( $cc != '' ) {
$mail->addCC( $cc );
}
if ( $bcc != '' ) {
$mail->addBCC( $bcc );
}
// Attachments
if ( $attachment != '' ) {
$mail->addAttachment( $attachment,"QueryDocument" ); // Add attachments
}
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body."<br><br>Thanks & Regards,<br><a href='https://lms.titanslab.in'>Learning Management System<br></a><h5>This was automatically generated email, Please do not reply.</h5>";
$mail->AltBody = strip_tags($body);
$mail->send();
return true;
} catch (Exception $e) {
return false;
// echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}