Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. </head>
  6. <body>
  7. <h1>Send message</h1>
  8. <form method="message.php" action="get">
  9.     <input type="text" name="subject" placeholder="subject">
  10.     <input type="text" name="text_field" placeholder="Write something...">
  11.     <button type="submit" value="submit" class="submit">Submit</button>
  12. </form>
  13.  
  14. </body>
  15. </html>
  16.  
  17.  
  18. <?php
  19. $servername = "localhost";
  20. $username = "root";
  21. $password = "";
  22. $dbname = "pros_si";
  23.  
  24. $recipients = array();
  25.  
  26.  
  27. // Create connection
  28. $conn = new mysqli($servername, $username, $password, $dbname);
  29.  
  30. // Check connection
  31. if ($conn->connect_error) {
  32.     die("Connection failed: " . $conn->connect_error);
  33. } else {
  34.     Echo "Connection succeded";
  35. }
  36.  
  37. if(isset($_GET['subject']) and isset($_GET['text_field'])){
  38.     $mail_subject = $_GET['subject'];
  39.     $text_field = $_GET['text_field'];
  40.     $message_id = rand(1,20);
  41.  
  42. }
  43.  
  44. //recolher emails que sao cliente para enviar
  45. $email_received = "SELECT email FROM users WHERE client_type = 1";
  46. $result = $conn->query($email_received);
  47.  
  48.  
  49.  
  50.  
  51.  
  52. $email_sent = "INSERT INTO mensagens (id, field)
  53. VALUES ('$message_id' , '$text_field')";
  54.  
  55. //guarda no array todos os emails dos clients
  56. while($row = mysqli_fetch_array($result2)) {
  57.     $emails[] = $row['email'];
  58. }
  59.     $to = implode("," ,$emails);
  60. $result2 = ("SELECT * FROM users WHERE WHERE client_type = 0")
  61.  
  62.     $body = $result2;
  63.      $body = $result2['username'];
  64.     mail($to, 'Subject', $body);
  65.  
  66. if ($conn->query($email_sent) === TRUE) {
  67.     echo "New entry on table messages";
  68. } else {
  69.     echo "Vão-se todos foder";
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement