-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
60 lines (47 loc) · 1.94 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
54
55
56
57
58
59
60
<?php
session_start();
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'config.php';
require '../connect.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (session_id() == '' || !isset($_SESSION) || !isset($_SESSION['user']) || $_SESSION['user'] == '') {
header("location:login.php");
exit;
}
$user = $_SESSION["user"];
$email = $_POST["email"];
$comments = $_POST["comments"];
// Log in database
$query = mysqli_query($con, "INSERT into postal_notification(sender,recipient,comments)VALUES('$user','$email','$comments')") or die(mysqli_error($con));
// Send email
$subject = "Postal Notification";
$body = "This is to inform you that a post/mail package is available for collection for you. ";
$body .= "You may pick up the same from your hostel's hall manager's office.\n\n";
if ($comments) {
$body .= "Comments:\n$comments\n\n";
}
$body .= "----------------\nThis email was generated just for you by postal notification system\n----------------";
$mail = new PHPMailer();
$mail->SMTPDebug = 0;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp-auth.iitb.ac.in";
$mail->Port = 25;
$mail->IsHTML(false);
$mail->Username = $smtp_user;
$mail->Password = $smtp_pass;
$mail->SetFrom("[email protected]", "Hall Manager");
$mail->addAddress($email);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
header("location:index.php?success=1");
}
$con->close();
?>