-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
126 lines (101 loc) · 4.67 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
use PHPMailer\PHPMailer\PHPMailer;
session_start();
ob_start();
include_once 'db.php';
$tsubject = $mysqli->escape_string($_POST['subject']);
//echo '<br>';
$tdate = $mysqli->escape_string($_POST['date']);
//echo '<br>';
$tcontent = $mysqli->escape_string($_POST['content']);
//Resetting Flag Before Mailing
if (isset($_POST['reset_flag'])) {
$mysqli->query("UPDATE mail SET flag=0 ");
$mysqli->query("UPDATE receiver SET flag=0 ");
header('location:index.php');
} else if (isset($_POST['submit_mail'])) {
//Checking Body And Subject
if (empty($tcontent) || empty($tsubject)) {
$_SESSION['error_msg'] = 'Content And Subject Cannot Be Leave Empty';
header('location:index.php');
} else {
// PHP FILE UPLOAD SCRIPT
if (!empty($_FILES['image_upload'])) {
$errors = array();
$file_name = $_FILES['image_upload']['name'];
$file_size = $_FILES['image_upload']['size'];
$file_tmp = $_FILES['image_upload']['tmp_name'];
$file_type = $_FILES['image_upload']['type'];
$file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
//Checking Extensions
$expensions = array("jpeg", "jpg", "png", "pdf");
if (in_array($file_ext, $expensions) === false) {
$errors[] = "extension not allowed, please choose a JPEG ,PDF or PNG file.";
}
//Checking Size
if ($file_size > 5242880) {
$errors[] = 'File size must be less than 5 MB';
}
//Upload To Path Provided
$img_name = $tdate;
if (empty($errors) == true) {
move_uploaded_file($file_tmp, "asset/images/" . $img_name . '.' . $file_ext);
// echo "Success";
} else {
//echo 'fail';
print_r($errors);
}
}
//Mailing Process Start Here
//Query For Sender Selecting Email From Mail Tables
$result_from = $mysqli->query(" SELECT * From mail where flag=0");
while ($row_from = $result_from->fetch_assoc()) {
// echo $row_from['email_id'];
//Query For Receiver Selecting Emails From Receiver Table Limit To 499 Per Head
$result_to = $mysqli->query("select * from receiver where flag=0 limit 499");
while ($row_to = $result_to->fetch_assoc()) {
$row_to['email_id'];
//PHP Mailing Script
require './vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'tls://smtp.gmail.com:587';
//$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $row_from['email_id'];
$mail->Password = "Password Here";
$mail->setFrom('[email protected]','example name');
$mail->addReplyTo('[email protected]');
$mail->addAddress( $row_to['email_id'],'example name');
$mail->Subject = "'" . $tsubject . "'";
$mail->msgHTML("'" . $tcontent . "'");
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo ' Sent' . $mail->ErrorInfo;
echo '<br>';
echo $row_to['email_id'] . '<br>';
//echo "UPDATE receiver SET flag=1,date='$trating_date' WHERE email_id='" . $row_to['email_id'] . "'" . "<br>";
$mysqli->query("UPDATE receiver SET flag=1,date='$trating_date' WHERE email_id='" . $row_to['email_id'] . "'");
}
$mail->ClearAddresses();
}
//echo "UPDATE mail SET flag=1,date='$trating_date' WHERE email_id='" . $row_from['email_id'] . "'" . '<br>';
$mysqli->query("update mail set flag=1,date='$trating_date' where email_id='" . $row_from['email_id'] . "'");
}
function save_mail($mail)
{
//You can change 'Sent Mail' to any other folder or tag
$path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
//Tell your server to open an IMAP connection using the same username and password as you used for SMTP
$imapStream = imap_open($path, $mail->Username, $mail->Password);
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
imap_close($imapStream);
return $result;
}
header('location:index.php');
}
}