如何从php中的数组向用户发送电子邮件?

时间:2017-04-24 15:16:49

标签: php

看。这是我的代码,用于从我的数据库中为用户发送电子邮件,这些用户是在ne array中输入的。 在那种情况下你能帮帮我吗?

  <?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 profesor@site.ro" ;
    mail($to, $subject, $body, $headers);
$conn->close();
  ?>

1 个答案:

答案 0 :(得分:2)

Pair::getRight上的{p> implode代替,即:

,