-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmailer.php
38 lines (31 loc) · 1.31 KB
/
mailer.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
function sendMail($email,$subject,$msg){
$mail = new PHPMailer(true);
try {
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com;';
$mail->SMTPAuth = true;
$mail->Username = smtp_email;
$mail->Password = smtp_pass;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$site_link = ($_SERVER['SERVER_NAME'] === '127.0.0.1')?$_SERVER['SERVER_NAME'] .'.com':$_SERVER['SERVER_NAME'];
$mail->setFrom('noreply@'.$site_link.'', ''.site_name.' Support');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Body = $msg;
$mail->Subject = $subject;
$mail->send();
return true;
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
return false;
}
}
?>