Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo "<table style='border: solid 1px black;'>";
- echo "<tr><th>Id</th><th>First Name</th><th>Last Name</th><th>Email Address</th><th>Phone Num</th><th>Treatment</th><th>Date</th><th>Time</th><th>Message</th><th>Reply</th></tr>";
- class TableRows extends RecursiveIteratorIterator {
- function __construct($it) {
- parent::__construct($it, self::LEAVES_ONLY);
- }
- function current() {
- return "<td style='width:100px;border:1px solid black;'>" . parent::current(). "</td>";
- }
- function beginChildren() {
- echo "<tr>";
- }
- function endChildren() {
- echo "</tr>" . "n";
- }
- }
- $servername = "#";
- $username = "#";
- $password = "#";
- $dbname = "#";
- try {
- $conn = new PDO("mysql: host=$servername; dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $stmt = $conn->prepare("SELECT Booking_request_form.id_booking, Client_Information.first_name, Client_Information.last_name, Client_Information.email_address, Client_Information.phone_number, Booking_request_form.treatment, Booking_request_form.date, Booking_request_form.time, Booking_request_form.message FROM Booking_request_form INNER JOIN Client_Information WHERE Client_Information.id_client=Booking_request_form.client_fk");
- $stmt->execute();
- // set the resulting array to associative
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
- echo $v;
- }
- }
- catch(PDOException $e) {
- echo "Error: " . $e->getMessage();
- }
- $conn = null;
- echo "</table>";
- ?>
- <?php
- $to = 'Emails from html table';
- $subject = 'Booking Information';
- $body = 'Dear # ,'."nn".'Your appointment for # at # on the # has been confirmed.'."nn".'Please do not reply to this email as it has been automated.';
- $headers = 'From: Beauty Factory Clinic <noreply@beautyfactoryclinic.co.uk>';
- if (mail($to, $subject, $body, $headers)) {
- echo 'Email has been sent to '.$to;
- } else {
- echo 'There was an error sending the email.';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement