PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/views/SEIP_142969/SummaryOfOrganization/email.php

https://gitlab.com/nz_moon/Nazmun_nahar_SEIP_ID_142969_B35_Atomic_Project
PHP | 231 lines | 185 code | 40 blank | 6 comment | 9 complexity | ecaab0fcdffd1bbc4177ec265281d41f MD5 | raw file
  1. <?php
  2. session_start();
  3. ################################# Update Information Here ##########################
  4. $yourGmailAddress = "nazmun.bitm@gmail.com"; #<<<<<<<<<<<<<< Set Your Email Address
  5. $gmailPassword = "12345678912345"; #<<<<<<<<<<<<<< Set Your Gmail Password
  6. ####################################################################################
  7. include_once('../../../vendor/autoload.php');
  8. require '../../../vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
  9. use App\SummaryOfOrganization\SummaryOfOrganization;
  10. use App\Utility\Utility;
  11. use App\Message\Message;
  12. $SummaryOfOrganization = new SummaryOfOrganization();
  13. if(isset($_REQUEST['list'])) {
  14. $list = 1;
  15. $recordSet = $SummaryOfOrganization->index();
  16. }
  17. else {
  18. $list= 0;
  19. $SummaryOfOrganization->setData($_REQUEST);
  20. $singleItem = $SummaryOfOrganization->view("obj");
  21. }
  22. ?>
  23. <!DOCTYPE html>
  24. <head>
  25. <title>Email This To A Friend</title>
  26. <meta charset="utf-8">
  27. <meta name="viewport" content="width=device-width, initial-scale=1">
  28. <link rel="stylesheet" href="../../../resource/bootstrap/css/bootstrap.min.css">
  29. <script src="../../../resource/bootstrap/js/bootstrap.min.js"></script>
  30. <script src="../../../resource/bootstrap/js/jquery.min.js"></script>
  31. </head>
  32. <body >
  33. <div class="container">
  34. <h2>Email This To A Friend</h2>
  35. <form role="form" method="post" action="email.php<?php if(isset($_REQUEST['id'])) echo "?id=".$_REQUEST['id']; else echo "?list=1";?>">
  36. <div class="form-group">
  37. <label for="Name">Name:</label>
  38. <input type="text" name="name" class="form-control" id="name" placeholder="Enter name of the recipient ">
  39. <label for="Email">Email Address:</label>
  40. <input type="text" name="email" class="form-control" id="email" placeholder="Enter recipient email address here..."">
  41. <label for="Subject">Subject:</label>
  42. <input type="text" name="subject" class="form-control" id="subject" value="<?php if($list){echo "List of Organization recommendation";} else {echo "A single Organization recommendation";} ?>">
  43. <label for="body">Body:</label>
  44. <textarea disabled="disabled" contenteditable="false" rows="8" cols="160" name="body" >
  45. <?php
  46. if($list){
  47. $trs="";
  48. $sl=0;
  49. printf("\tSerial\t\t\t\tID\t\t\t\tOrganization Name\t\t\t\tOrganization Summary\n");
  50. foreach($recordSet as $row) {
  51. $id = $row["id"];
  52. $organization_name = $row['organization_name'];
  53. $organization_summary = $row['organization_summary'];
  54. $sl++;
  55. printf("\t\t%d\t\t\t\t%d\t\t\t\t%s\t\t\t\t%s\n",$sl,$id,$organization_name,$organization_summary);
  56. }
  57. }
  58. else
  59. {
  60. printf("I'm recommending You: [Organization ID:%s, Organization /name:%s, Organization Summary:%s]",$singleItem->id,$singleItem->organization_name,$singleItem->organization_summary);
  61. }
  62. ?>
  63. </textarea>
  64. </div>
  65. <input class="btn-lg btn-primary" type="submit" value="Send Email">
  66. </form>
  67. <?php
  68. if(isset($_REQUEST['email'])&&isset($_REQUEST['subject'])) {
  69. date_default_timezone_set('Etc/UTC');
  70. //Create a new PHPMailer instance
  71. $mail = new PHPMailer;
  72. //Tell PHPMailer to use SMTP
  73. $mail->isSMTP();
  74. //Enable SMTP debugging
  75. // 0 = off (for production use)
  76. // 1 = client messages
  77. // 2 = client and server messages
  78. $mail->SMTPDebug = 2;
  79. //Ask for HTML-friendly debug output
  80. $mail->Debugoutput = 'html';
  81. //Set the hostname of the mail server
  82. $mail->Host = 'smtp.gmail.com';
  83. // use
  84. // $mail->Host = gethostbyname('smtp.gmail.com');
  85. // if your network does not support SMTP over IPv6
  86. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  87. $mail->Port = 587; //587
  88. //Set the encryption system to use - ssl (deprecated) or tls
  89. $mail->SMTPSecure = 'tls'; //tls
  90. //Whether to use SMTP authentication
  91. $mail->SMTPAuth = true;
  92. //Username to use for SMTP authentication - use full email address for gmail
  93. $mail->Username = $yourGmailAddress;
  94. //Password to use for SMTP authentication
  95. $mail->Password =$gmailPassword;
  96. //Set who the message is to be sent from
  97. $mail->setFrom($yourGmailAddress, 'BITM PHP - 22');
  98. //Set an alternative reply-to address
  99. $mail->addReplyTo($yourGmailAddress, 'BITM PHP - 22');
  100. //Set who the message is to be sent to
  101. $mail->addAddress($_REQUEST['email'], $_REQUEST['name']);
  102. //Set the subject line
  103. $mail->Subject = $_REQUEST['subject'];
  104. //Read an HTML message body from an external file, convert referenced images to embedded,
  105. //convert HTML into a basic plain-text alternative body
  106. //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  107. //Replace the plain text body with one created manually
  108. $mail->AltBody = 'This is a plain-text message body';
  109. $recordSet = $SummaryOfOrganization->index();
  110. $trs="";
  111. $sl=0;
  112. foreach ($recordSet as $row) {
  113. $id = $row["id"];
  114. $organization_name = $row['organization_name'];
  115. $organization_summary = $row['organization_summary'];
  116. $sl++;
  117. $trs .= "<tr>";
  118. $trs .= "<td width='150'> $sl</td>";
  119. $trs .= "<td width='150'> $id </td>";
  120. $trs .= "<td width='300'> $organization_name </td>";
  121. $trs .= "<td width='300'> $organization_summary </td>";
  122. $trs .= "</tr>";
  123. }
  124. $html= <<<BITM
  125. <div class="table-responsive">
  126. <table class="table">
  127. <thead>
  128. <tr>
  129. <th align='left'>Serial</th>
  130. <th align='left'>ID</th>
  131. <th align='left'>Organization Name</th>
  132. <th align='left'>Organization Summary</th>
  133. </tr>
  134. </thead>
  135. <tbody>
  136. $trs
  137. </tbody>
  138. </table>
  139. BITM;
  140. ;
  141. if($list) $mail->Body = $html;
  142. else $mail->Body = "I'm recommending You [Book ID:". $singleItem->id.", Organization Name:".$singleItem->Organization_Summary."]";
  143. //Attach an image file,
  144. //$mail->addAttachment('images/phpmailer_mini.png');
  145. //send the message, check for errors
  146. if (!$mail->send()) {
  147. echo "Mailer Error: " . $mail->ErrorInfo;
  148. } else {
  149. Message::message("
  150. <div class=\"alert alert-success\">
  151. <strong>Success!</strong> Email has been sent successfully.
  152. </div>");
  153. //Utility::redirect("index.php");
  154. ?>
  155. <script type="text/javascript">
  156. window.location.href = 'index.php';
  157. </script>
  158. <?php
  159. }
  160. }
  161. ?>
  162. </div>
  163. </body>
  164. </html>