Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- </head>
- <body>
- <h1>Send message</h1>
- <form method="message.php" action="get">
- <input type="text" name="subject" placeholder="subject">
- <input type="text" name="text_field" placeholder="Write something...">
- <button type="submit" value="submit" class="submit">Submit</button>
- </form>
- </body>
- </html>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "pros_si";
- $recipients = array();
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- } else {
- Echo "Connection succeded";
- }
- if(isset($_GET['subject']) and isset($_GET['text_field'])){
- $mail_subject = $_GET['subject'];
- $text_field = $_GET['text_field'];
- $message_id = rand(1,20);
- }
- //recolher emails que sao cliente para enviar
- $email_received = "SELECT email FROM users WHERE client_type = 1";
- $result = $conn->query($email_received);
- $email_sent = "INSERT INTO mensagens (id, field)
- VALUES ('$message_id' , '$text_field')";
- //guarda no array todos os emails dos clients
- while($row = mysqli_fetch_array($result2)) {
- $emails[] = $row['email'];
- }
- $to = implode("," ,$emails);
- $result2 = ("SELECT * FROM users WHERE WHERE client_type = 0")
- $body = $result2;
- $body = $result2['username'];
- mail($to, 'Subject', $body);
- if ($conn->query($email_sent) === TRUE) {
- echo "New entry on table messages";
- } else {
- echo "Vão-se todos foder";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement