<?php		
	if (isset($_GET['complete_order'])) {
		    echo $order_id = intval($_GET['complete_order']);
			mysqli_query($con, "UPDATE orders SET order_complete = 1 WHERE order_id = $order_id");
			$get_record = mysqli_query($con, "SELECT * FROM orders WHERE order_id=$order_id");
			$get_row = mysqli_fetch_array($get_record);
			$email = $get_row['user_email'];
			$name = $get_row['user_name'];
			$order_number = $get_row['order_number'];
			
			$order_status = 'https://candycleansetools.com/tracking-order.php?id='.$order_number;
			
		$to = $email;
		$from = 'contact@candycleansetools.com';
		$subject = 'Your Candy Cleanse Order Has Shipped!';
	
		$message = '
			<html>
				<body class="em_body" style="margin: 0px auto; padding: 0px;" bgcolor="#efefef">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="em_full_wrap" bgcolor="#efefef">
					<tbody>
						<tr>
							<td align="center" valign="top">
								<table align="center" border="0" cellpadding="0" cellspacing="0" class="em_main_table" style="width: 650px; table-layout: fixed;" width="650" bgcolor="#ffffff">
									<!-- Start Pre header section -->
									<tbody style="background: url(images/bg.PNG) no-repeat;width:100px;background-position: center center;background-size: 600px;">
										<tr>
											<td align="center" style="background-color: #efefef; border-bottom: 3px solid white;">
												<table bgcolor="#efefef" border="0" cellpadding="0" cellspacing="0" class="em_wrapper" width="100%">
													<tbody>
														<tr>
															<td align="center" style="font-family: Helvetica, Arial, sans-serif; font-size: 10px; color: #8e8e8e; line-height: 20px; padding: 5px 0;">
																&nbsp;
															</td>
														</tr>
													</tbody>
												</table>
											</td>
										</tr>
										<!-- End Pre header section -->
										<tr>
											<td align="center" valign="top" style="padding: 20px 10px;">
												<a data-link-name="Candy Cleanse" href="https://candycleansetools.com/" target="_blank" title="Candy Cleanse">
													<img src="https://candycleansetools.com/images/logo-1.png" width="200" alt="Candy Cleanse" border="0" style="border-radius: 15px !important;float:center;max-width: 140px;height: auto; background: #ffffff; display: block; border: 0px;margin-bottom:10px" />
												</a>
												<b>ORDER #: '.$order_number.'</b>
												<p style="font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 10px; color: #1c1c1c; padding: 8px">
													<b>FROM:</b> 
													Candy Cleanse
													18851 NE 29th Ave 
													Suite 601
													Aventura, FL 33180
												</p>
											</td>
										</tr>
										<tr>
											<td align="left" valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 16px; line-height: 26px; color: #1c1c1c;">
												<!-- Start EMail Body -->
												<table>
													<tbody>
														<tr>
															<td align="left" valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 15px; line-height: 27px; color: #1c1c1c; padding: 20px 30px 8px 30px; font-weight: bold;">
																Dear '.$name.',
															</td>
														</tr>
														<tr>
															<td align="left" class="Pad_LR20" valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 15px; line-height: 26px; color: #1c1c1c; padding: 8px 40px 15px 30px;">
																<p>
																	Thank you for your order. It’s on the way! We are excited to hear how Candy Cleanse is working for you!
																</p>
																<p>
																	Tag @CoachStormy on your stories on Instagram and use #CandyCleanse. She’d love to feature you!
																</p>
																<p>
																	Track Order here: '.$order_status.'
																</p>
																<p>
																	<b>Here’s to your health!</b>
																</p>
																<p>
																	<b>The Candy Cleanse Team</b>
																</p>
															</td>
														</tr>
														</tr>
													</tbody>
												</table>
											</td>
										</tr>
										<tr>
											<td align="center" style="background-color: #f7f7f7;">
												<table bgcolor="#f7f7f7" border="0" cellpadding="0" cellspacing="0" class="em_wrapper" width="100%">
													<tbody>
														<tr>
															<td align="center" style="padding: 10px;" valign="top" class="Pad_LR22">
																<table align="center" border="0" cellpadding="0" width="600" cellspacing="0" style="width: 600px;" class="em_wrapper">
																	<tbody>
																		<tr>
																			<td align="center">
																				<table width="100%" border="0" cellspacing="0" cellpadding="0">
																					<tbody>
																						<tr>
																							<td
																								align="center"
																								valign="top"
																								style="font-family: Helvetica, Arial, sans-serif; font-size: 12px; line-height: 16px; color: black; padding: 8px 0px 0px 0px; text-align: left;"
																							>
																								<center><p>Copyright © - 2024 Stormy Wellington, Inc. All Rights Reserved.</p></center>
																								
																							</td>
																						</tr>
																					</tbody>
																				</table>
																			</td>
																		</tr>
																	</tbody>
																</table>
															</td>
														</tr>
													</tbody>
												</table>
											</td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
					</tbody>
				</table>
			</body>
		</html>';
		
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
		$headers .= 'From: ' . $from . "\r\n";
		mail($to,$subject,$message,$headers);
			
		header("location:order_details.php?id=$order_id");
		exit();
		
	}
	
	?>