1

Look. This is my code for sending emails for users from my DB, which are input in ne array. Can you help me in that situation?

  <?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "dbname";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Conexiune esuata: " . $conn->connect_error);
}    
$sql = mysqli_query($conn,"select email from mst_user");
    $recipients = array();
    while($row = mysqli_fetch_array($sql)) {
        $recipients[] = $row['email'];        
    }
print_r($recipients);
$to = implode(" ", $recipients);   
    $subject = htmlspecialchars($_POST["subject"]);
    $body = $_POST["mesaj"];
    $headers = "De la [email protected]" ;
    mail($to, $subject, $body, $headers);
$conn->close();
  ?>
1
  • You should include solutions you've tried in your question. Please read How do I ask a good question? Commented Apr 24, 2017 at 15:35

1 Answer 1

2

implode on , instead, i.e.:

$to = implode(",", $recipients);   
Sign up to request clarification or add additional context in comments.

1 Comment

My vector look like, and the email do not send to this user's emails.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.