PHP mail MYSQL DB

66 views Asked by At

Hello people from stackoverflow. I need some help with an PHP script I have.. The problem is that it isn't sending any email. I tried a couple of other topics but it didn't work quite well..

Here is my mailing (Config is already been included) code:

    <?php
$sql = "SELECT email FROM users";
    $res = mysql_query($sql) or die(mysql_error());

    while($row = mysql_fetch_assoc($res) )
    {
         $area .= $row['email']. ", ";  

    }
?>
<?php
if(isset($_POST['submit'])){


$email_list = explode(',', $area);
$message = $_REQUEST['bericht'];
$to = $email_list;

@mail($to,"Message","$message". "\n\n". "Met vriendelijke groet,". "\n". "Brian","From: noreply@$siteurl");
}
?>

What is wrong with this code? Thanks!

1

There are 1 answers

3
Mattt On BEST ANSWER
    <?php
$sql = "SELECT email FROM users";
    $res = mysql_query($sql) or die(mysql_error());

    while($row = mysql_fetch_assoc($res) )
    {
         $area .= $row['email']. ", ";  

    }
?>
<?php
if(isset($_POST['submit'])){

$message = $_REQUEST['bericht'];
$to = $area;

@mail($to,"Message","$message". "\n\n". "Met vriendelijke groet,". "\n". "Brian","From: noreply@$siteurl");

Take out the explode and try with just the code above. mail() wants multiple address in the to field separated by commas, so it doesn't make any sense to explode them on commas. As andrewsi said, that is then passing to the mail function as an array.