Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. <?php
  2.  
  3. echo "<table style='border: solid 1px black;'>";
  4. 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>";
  5.  
  6. class TableRows extends RecursiveIteratorIterator {
  7. function __construct($it) {
  8. parent::__construct($it, self::LEAVES_ONLY);
  9. }
  10.  
  11. function current() {
  12. return "<td style='width:100px;border:1px solid black;'>" . parent::current(). "</td>";
  13. }
  14.  
  15. function beginChildren() {
  16. echo "<tr>";
  17. }
  18.  
  19. function endChildren() {
  20. echo "</tr>" . "n";
  21. }
  22. }
  23.  
  24. $servername = "#";
  25. $username = "#";
  26. $password = "#";
  27. $dbname = "#";
  28.  
  29. try {
  30. $conn = new PDO("mysql: host=$servername; dbname=$dbname", $username, $password);
  31. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  32. $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");
  33.  
  34. $stmt->execute();
  35.  
  36. // set the resulting array to associative
  37. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  38. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
  39. echo $v;
  40. }
  41. }
  42.  
  43. catch(PDOException $e) {
  44. echo "Error: " . $e->getMessage();
  45. }
  46.  
  47. $conn = null;
  48. echo "</table>";
  49. ?>
  50.  
  51. <?php
  52.  
  53. $to = 'Emails from html table';
  54. $subject = 'Booking Information';
  55. $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.';
  56. $headers = 'From: Beauty Factory Clinic <noreply@beautyfactoryclinic.co.uk>';
  57.  
  58. if (mail($to, $subject, $body, $headers)) {
  59. echo 'Email has been sent to '.$to;
  60. } else {
  61. echo 'There was an error sending the email.';
  62. }
  63.  
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement