I want send mail which I generate from my database but I don't know how send them.
include 'conectar.php';
$result = mysqli_query($conexion, "SELECT `Email` FROM `usuarios`");
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "company@company.com.mx";
$to = while ($row = mysqli_fetch_array($result)) {
echo $row[0]; echo ",";
};
$subject = "El elemento fue actualizado a la version ";
$message = "El elemento fue actualizado";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
First, I will not recommend using the mail() function to send email to multiple recipients separated with commas.
I will recommend you use SMPP classes like PHPMailer: https://github.com/PHPMailer/PHPMailer
Having said that, correct your code this:
ini_set( 'display_errors', 1 ); error_reporting( E_ALL );
include 'conectar.php';
$result = mysqli_query($conexion, "SELECT `Email` FROM `usuarios`");
$from = "company@company.com.mx";
$to = "";
while ($row = mysqli_fetch_assoc($result)) {
$to .= $row['Email'].",";
}
$to = rtrim($to); //remove any trailing conna
$subject = "El elemento fue actualizado a la version ";
$message = "El elemento fue actualizado";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
Pay attention to how I rearranged your original code.