Guest User

Untitled

a guest
Jun 19th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'mandrill-api-php/src/Mandrill.php';
  4.  
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. $table = '';
  9.  
  10. $conn = mysql_connect($servername, $username, $password);
  11.  
  12.  
  13. if (!$conn) {
  14. die("Connection failed: " . mysqli_connect_error());
  15. }
  16.  
  17.  
  18.  
  19. $selected = mysql_select_db("DB Name")
  20. or die("Could not select database");
  21.  
  22. $query=mysql_query(Query);
  23.  
  24.  
  25. $table .= "<table width='auto' height='auto' border='1' bordercolor='#003399' style='color:#FF0000;table-layout:fixed' cellpadding=0 cellspacing=0>
  26. <tr>
  27. <th>User ID</th>
  28. <th>Full Name</th>
  29. <th>Username</th>
  30. <th>Email ID</th>
  31.  
  32. </tr>";
  33.  
  34. while($row = mysql_fetch_array($query))
  35. {
  36. $table .= "<tr>";
  37. $table .= "<td>" . $row['id'] . "</td>";
  38. $table .= "<td>" . $row['fullname'] . "</td>";
  39. $table .= "<td>" . $row['username'] . "</td>";
  40. $table .= "<td>" . $row['useremail'] . "</td>";
  41. $table .= "</tr>";
  42. }
  43. $table .= "</table><br>";
  44.  
  45.  
  46. try {
  47. $mandrill = new Mandrill(API Key);
  48. $message = array(
  49. 'html' => $table,
  50. 'subject' => 'Notification Email',
  51. 'from_email' => 'Example@example.com',
  52. 'from_name' => 'Test',
  53. 'to' => array(
  54. array(
  55. 'email' => 'Example@example.com',
  56. 'name' => 'Test',
  57. 'type' => 'to'
  58. )
  59. ),
  60. 'important' => false,
  61. 'track_opens' => null,
  62. 'track_clicks' => null,
  63. 'auto_text' => null,
  64. 'auto_html' => null,
  65. 'inline_css' => null,
  66. 'url_strip_qs' => null,
  67. // A mandrill error occurred: Mandrill_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
  68. throw $e;
  69. }
  70. ?>
  71. 'preserve_recipients' => null,
  72. 'view_content_link' => null,
  73. 'tracking_domain' => null,
  74. 'signing_domain' => null,
  75. 'return_path_domain' => null,
  76.  
  77. );
  78. $async = false;
  79. $result = $mandrill->messages->send($message, $async);
  80. print_r($result);
  81.  
  82.  
  83. }
  84. catch(Mandrill_Error $e) {
  85.  
  86. echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
  87.  
  88. throw $e;
  89. }
  90. ?>
  91.  
  92. <pre>/*
  93. Before coding, you have to make configurations in Mandrill.
  94.  
  95. Step 1: Enter Mandrill and register your domain.
  96.  
  97. Step 2: Configure DNS: DKIM and SPF (This is a good tutorial: https://www.youtube.com/watch?v=uEjP_smeLjU) at https://mandrillapp.com/settings/sending-domains
  98.  
  99. Step 3: Get a KEY API (https://mandrillapp.com/settings)
  100.  
  101. Step 4: Code with PHP
  102.  
  103. Step 5: Good luck! :)
  104. */
  105.  
  106.  
  107. /*LIBS*/
  108. include 'lib/mandrill-api-php/src/Mandrill.php';
  109. $mandrill = new Mandrill('YOUR API KEY HERE');
  110.  
  111. /*ADMIN AND USER EMAIL*/
  112. $admin_email = 'your_email@your_domain.com';
  113. $client_email = 'the_email_of_the_client@mail.com';
  114.  
  115. /*attach PDF*/
  116. $attachment = file_get_contents('the_route_to_your_pdf');
  117. $attachment_encoded = base64_encode($attachment);
  118.  
  119. try{
  120. $user_message = array(
  121. 'subject' => 'Guía del descanso Pikolín',
  122. 'from_email' => $admin_email,
  123. 'from_name' => 'Pikolín',
  124. 'html' => '<p>Aquí va la plantilla HMTL</p>',
  125. 'to' => array(array('email' => $client_email, 'name' => 'Recipient 1')),
  126. 'merge_vars' => array(array(
  127. 'rcpt' => 'recipient1@domain.com',
  128. 'vars' =>
  129. array(
  130. array(
  131. 'name' => 'FIRSTNAME',
  132. 'content' => 'Recipient 1 first name'),
  133. array(
  134. 'name' => 'LASTNAME',
  135. 'content' => 'Last name')
  136. ))),
  137. 'attachments' => array(
  138. array(
  139. 'content' => $attachment_encoded,
  140. 'type' => "application/pdf",
  141. 'name' => 'the_name_of_the_attach.pdf',
  142. ))
  143. );
  144.  
  145. $res_user_mandrill = $mandrill->messages->send($user_message, $async=false, $ip_pool=null, $send_at=null);
  146.  
  147. } catch(Mandrill_Error $e) {
  148.  
  149. }
  150.  
  151. </pre>
Add Comment
Please, Sign In to add comment