php - sending email to all subscribed users, selecting from sql DB and sending, not working -


i have html input form user can subscribe newsletter. enter first name, last name , email , added table in sql database.

i have created second html form "admin" can enter subject , message in body textbox , click send.

now supposed happen when click send is, subject/body sent users in sql database, not working! please? code below:

<?php  $user = "example";  $password = "example";  $host = "example";  $dbase = "example";  $table = "example";   $from= 'example';//specify here address want email sent  $subject= $_post['subject']; $body= $_post['body'];  // connection dbase  $dbc= mysqli_connect($host,$user,$password, $dbase)  or die("unable select database");  $query= "select * $table"; $result= mysqli_query ($dbc, $query)  or die ('error querying database.');  while ($row = mysqli_fetch_array($result)) { $firstname= $row['firstname']; $lastname= $row['lastname']; $email= $row['email'];  $msg= "dear $firstname $lastname,\n$body"; mail($to, $subject, $msg, 'from:' . $from); echo 'email sent to: ' . $email. '<br>'; }  mysqli_close($dbc); ?> 

i confirmation @ end "email sent (and display email)", not send , "undefined variable: to" on line 28.

(i have put example on purpose @ top)

in code

while ($row = mysqli_fetch_array($result)) {   $firstname= $row['firstname'];   $lastname= $row['lastname'];   $email= $row['email'];    $msg= "dear $firstname $lastname,\n$body";   mail($to, $subject, $msg, 'from:' . $from);   echo 'email sent to: ' . $email. '<br>'; } 

your email address stored in $email sending email $to. mail line should be:

mail($email, $subject, $msg, 'from:' . $from); 

also, should configure server accordingly mail() work. read more @ http://ie1.php.net/manual/en/function.mail.php


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -