-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendMail.php
203 lines (177 loc) · 7.42 KB
/
sendMail.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
require("assets/sendgridMail/sendgrid-php.php");
require 'config.php';
session_start();
//(works on epizy server)
if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn']===TRUE) {
if ($_SESSION['orderConfirmed']===TRUE && isset($_POST['order_confirmation_mail']) && $_POST['order_confirmation_mail']=="true") {
$_SESSION['orderConfirmed']=FALSE;
$_POST['order_confirmation_mail']="false";
$safeOid = preg_replace('/[^\w]/','',$_POST['order_id']);
$email = new \SendGrid\Mail\Mail();
$SENDER_NAME = "MuskGreen Support";
$SENDER_MAIL = "mgs@muskgreen.live";
$email->setFrom($SENDER_MAIL, $SENDER_NAME);
$email->setSubject("Order Confirmed");
$email->addTo($_SESSION['userEmail'], "".$_SESSION['userFName']." ".$_SESSION['userLName']);
$sql="SELECT paymentMethod, productorder.addressName, locality, area, landmark, city, pincode, state, phone FROM deliveryaddress NATURAL JOIN productorder WHERE oid = '".$safeOid."'";
$result=$conn->query($sql);
$address='';
$paymentMethod='';
while ($row=$result->fetch_assoc()) {
$address=$address.$row["addressName"].': '.$row["locality"].', '.$row["area"];
if ($row['landmark']!='') {
$address=$address.', Near '.$row["landmark"];
}
$address=$address.', '.$row["city"].', '.$row["state"].' - '.$row["pincode"].', Contact: '.$row["phone"];
$paymentMethod=$row['paymentMethod'];
}
$productsRows='';
$allProductsPrice=0;
$prdArray = json_decode($_COOKIE['productsBuyList'], true);
setcookie('productsBuyList', json_encode($prdArray), time()-60*60*365);
while ($row=array_pop($prdArray)) {
$productsRows=$productsRows.'<tr>
<td style="padding-left: 4px; padding-right: 4px;">'.$row[0].'</td>
<td style="padding-left: 4px; padding-right: 4px;">
<span style="max-width: 8rem;">
'.$row[1].'
</span>
</td>
<td style="padding-left: 4px; padding-right: 4px;">'.$row[2].'</td>
<td style="padding-left: 4px; padding-right: 4px;">'.$row[3].'</td>
</tr>';
$allProductsPrice=$allProductsPrice+floatval($row[3]);
}
if ($allProductsPrice<=599) {
$allProductsPrice=$allProductsPrice+30;
}
$MAIL_CONTENT = '<div style="padding: 0rem;">
<div style="background-color: #509534; padding: 0.5rem; color: #fff; border-radius: 5px;"><center><h2>MuskGreen Order</h2></center></div>
<div style="padding-left: 1rem; padding-right: 1rem;">
<p style="color: #66BB6A !important;">
Hi '.$_SESSION['userFName'].', thank you for your Green order. <small>We are processing your order and shall arrive soon.<br><br>
Here are the details:</small>
</p>
<div style="max-width: 18rem; border: 1px solid #66BB6A; border-radius: 4px; padding: 1rem;">
<div>
<span style="max-width: 12rem;">
<b>Order ID:</b> '.$safeOid.'
</span><br>
<span style="max-width: 12rem;">
<b>Payment Method:</b> '.$paymentMethod.'
</span><br>
<small>'.$address.'</small>
</div>
</div>
<br>
<table>
<thead style="color:#fff; background-color: #66BB6A;">
<tr>
<th>#</th>
<th>Product</th>
<th>Quant</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
'.$productsRows.'
</tbody>
</table>
<br>
<div style="max-width: 18rem; border: 1px solid #66BB6A; border-radius: 4px; padding: 1rem;">
<div>
<span style="max-width: 12rem;">
<b>Order Total:</b> Rs. '.$allProductsPrice.'*
</span><br>
<span style="max-width: 12rem;">
<b>Delivery Time:</b> 2-4 days
</span><br>
<small>* Price inclusive of GST</small>
</div>
</div>
<br>
<p style="color: #66BB6A !important;">We would love to see you back.</p>
<div style="background-color: #66BB6A; color: #fff; font-size: 1.1rem; padding: 2rem; font-weight: 600; border-radius: 8px;">
<center>
Next Morning Delivery of Fruits and Vegetables in Dehradun...<br>
Service starts soon.
</center>
</div>
<br><br>
<center>MuskGreen<br>34, Kunj Vihar, Dehradun, Uttarakhand<br>Contact: info@muskgreen.live</center>
</div>
</div>';
$email->addContent("text/html", $MAIL_CONTENT);
$sendgrid = new \SendGrid("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");
try {
$response = $sendgrid->send($email);
// print $response->statusCode() . "\n";
// print_r($response->headers());
// print $response->body() . "\n";
} catch (Exception $e) {
}
$email = new \SendGrid\Mail\Mail();
$SENDERN = "MuskGreen Order";
$SENDERM = "new.order@muskgreen.live";
$email->setFrom($SENDERM, $SENDERN);
$email->setSubject("New Order - MG Internals");
$email->addTo('kartikbitcoins@gmail.com', 'Kartikeya Kapparwan');
$MAIL_CONTENT = '<div style="padding: 0rem;">
<div style="background-color: #509534; padding: 0.5rem; color: #fff; border-radius: 5px;"><center><h2>New Order</h2></center></div>
<div style="padding-left: 1rem; padding-right: 1rem;">
<p style="color: #66BB6A !important;">
Hey Orders Department, Details of new order.
</p>
<div style="max-width: 18rem; border: 1px solid #66BB6A; border-radius: 4px; padding: 1rem;">
<div>
<span><b>'.$_SESSION['userFName'].' '.$_SESSION['userLName'].'</b></span><br>
<span style="max-width: 12rem;">
<b>Order ID:</b> '.$safeOid.'
</span><br>
<span style="max-width: 12rem;">
<b>Payment Method:</b> '.$paymentMethod.'
</span><br>
<small>'.$address.'</small>
</div>
</div>
<br>
<table>
<thead style="color:#fff; background-color: #66BB6A;">
<tr>
<th>#</th>
<th>Product</th>
<th>Quant</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
'.$productsRows.'
</tbody>
</table>
<br>
<div style="max-width: 18rem; border: 1px solid #66BB6A; border-radius: 4px; padding: 1rem;">
<div>
<span style="max-width: 12rem;">
<b>Order Total:</b> Rs. '.$allProductsPrice.'*
</span><br>
<span style="max-width: 12rem;">
<b>Delivery Time:</b> 2-4 days
</span><br>
<small>* Price inclusive of GST</small>
</div>
</div>
<br><br>
<center>Verify the order first.</center>
</div>
</div>';
$email->addContent("text/html", $MAIL_CONTENT);
$sendgrid = new \SendGrid("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");
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
}
$conn->close();
}
}
?>