-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_sending.php
60 lines (44 loc) · 1.42 KB
/
mail_sending.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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function send_mail($receiver, $subject, $body)
{
// mail sending
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
$sender_email = '[email protected]';
$sender_pass = 'zhnwjshfvcxoeerk';
//Enable verbose debug output
$mail->SMTPDebug = 0; //SMTP::DEBUG_SERVER;
//Send using SMTP
$mail->isSMTP();
//Set the SMTP server to send through
$mail->Host = 'smtp.gmail.com';
//Enable SMTP authentication
$mail->SMTPAuth = true;
//SMTP username
$mail->Username = $sender_email;
//SMTP password
$mail->Password = $sender_pass;
//Enable TLS encryption;
// $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
//TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$mail->Port = 587;
//Recipients
$mail->setFrom($sender_email, '3rd-ichss.jkkniu.edu.bd');
//Add a recipient
$mail->addAddress($receiver);
$mail->addReplyTo($sender_email);
//Set email format to HTML
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
if ($mail->send()) {
$mail->ClearAddresses();
$mail->clearReplyTos();
}
}