query($sqlpId); if ($resultpId->num_rows > 0) { // output data of each row while($rowpId = $resultpId->fetch_assoc()) { $propertyCode = $rowpId["PROPERTY_CODE"]; $guestEmail = $rowpId["GUEST_EMAIL"]; } } $sql = "SELECT Id, GUEST_NAME, EMAIL_ADDR, PIN_CODE, CHECK_IN_DATE, CHECK_OUT_DATE FROM AIRBNB_BOOKINGS WHERE STATUS='ACTIVE' AND EMAIL_SENT_AT IS NULL AND Id=" . $bookId; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row $row = $result->fetch_assoc(); $guestId = $row["Id"]; $guestName = $row["GUEST_NAME"]; $splitName = explode(" ", $guestName); $guestFirstName = $splitName[0]; $guestLastName = $splitName[1]; $emailAddress = $row["EMAIL_ADDR"]; $pinCode = $row["PIN_CODE"]; $checkInDate = $row["CHECK_IN_DATE"]; $checkOutDate = $row["CHECK_OUT_DATE"]; $recordCount = "send"; } else { echo "No emails to be sent!"; } //email variables $to = $emailAddress; //$to = 'cwill207@gmail.com'; $from = 'unit3415@freedomsailcharters.com'; $from_name = 'Craig & Samantha Williams'; $ccs = 'kellnjgirl3@aol.com'; $bccs = 'samantha30312@gmail.com,cwill207@gmail.com'; $checkInDate = date_format(date_create($checkInDate), "m/d/Y"); $checkOutDate = date_format(date_create($checkOutDate), "m/d/Y"); //attachment files path array $files = array('/home/cwill207/public/slooptravel/airbnb/docs/check-in-3415.pdf','/home/cwill207/public/slooptravel/airbnb/docs/check-out.pdf'); $subject = 'Your Stay in Hilton Head: ' . $checkInDate . " - " . $checkOutDate; $html_content = ''; $html_content = $guestEmail . ''; $html_content = str_replace("{guestFirstName}", $guestFirstName, $html_content); $html_content = str_replace("{pinCode}", $pinCode, $html_content); $html_content = str_replace("{propertyCode}", $propertyCode, $html_content); $html_content = str_replace("{checkInDate}", $checkInDate, $html_content); $html_content = str_replace("{checkOutDate}", $checkOutDate, $html_content); //==================== if($recordCount == 'send'){ //call multi_attach_mail() function and pass the required arguments $send_email = multi_attach_mail($to, $ccs, $bccs, $subject,$html_content,$from,$from_name,$files); } //print message after email sent if($send_email){ //echo "Mail Sent!
"; $sql = "UPDATE AIRBNB_BOOKINGS SET EMAIL_SENT_AT=NOW() WHERE Id = " . $guestId; if ($conn->query($sql) === TRUE) { echo "Email Sent to: " . $guestName . " <" . $emailAddress . ">\r\n"; } else { echo "this didn't work"; } echo "Database updated to reflect email sent time\r\n"; } else { echo "No emails to be sent!"; } $conn->close(); } function multi_attach_mail($to, $ccs, $bccs, $subject, $message, $senderMail, $senderName, $files){ $from = $senderName." <".$senderMail.">"; $headers = "From: $from"; $headers .= "\nCc: $ccs"; $headers .= "\nBcc: $bccs"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // preparing attachments if(count($files) > 0){ for($i=0;$istart_time = $this->getmicrotime(); } function stop() { $this->end_time = $this->getmicrotime(); } function result() { if (is_null($this->start_time)) { exit('Timer: start method not called !'); return false; } else if (is_null($this->end_time)) { exit('Timer: stop method not called !'); return false; } return round(($this->end_time - $this->start_time), 4); } # an alias of result function function time() { $this->result(); } } ?>