query($sql_insert) === true) { //Invio mail a tutti $sql = "SELECT * FROM users"; $result = mysqli_query($con, $sql); if ($result->num_rows > 0) { while ($row = mysqli_fetch_assoc($result)) { $email = new \SendGrid\Mail\Mail(); $email->setFrom("info@n-hub.com", "NH-HR"); $email->addTo("" . $row["email"] . "", "" . $row["name"] . " " . $row["surname"] . ""); $email->SetTemplateId("d-55b033ba0ed74378a00855406e634540"); //Here is the Place holder values you need to replace. $email->addDynamicTemplateData("NHHR_oggetto_pubblicazione", "" . $object . ""); $email->addDynamicTemplateData("NHHR_corpo_pubblicazione", "" . $body . ""); $email->addDynamicTemplateData("NHHR_data_pubblicazione", "" . date('d/m/Y H:i', strtotime($datetime)) . ""); $sendgrid = new \SendGrid(SENDGRID_API_KEY); try { $response = $sendgrid->send($email); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage() . "\n"; } } } echo "ok"; } else { echo "error"; } $con->close();