php - Email application -


i trying make simple application send out emails email addresses in database. i'm using phpmailer. line not working: $mail->addaddress($to, "test message"); works if, instead of $to, type email address. need send emails every email in database.

if ((!empty($subject)) && (!empty($text))) {    $query = "select * email_list";   $result = mysqli_query($dbc, $query)     or die('error querying database.');    while ($row = mysqli_fetch_array($result)){      $to = $row['email'];     $mail->addaddress($to, "test message");      $subject = $_post['subject'];     $text = $_post['elvismail'];     $first_name = $row['first_name'];     $last_name = $row['last_name'];     $msg = "dear $first_name $last_name,\n$text";     mail($to, $subject, $msg, 'from:' . $from);     echo 'email sent to: ' . $to . '<br />';   }     mysqli_close($dbc); } 

so, phpmailer. not mix phpmailer , php mail() functions.

if ((!empty($subject)) && (!empty($text))) {     $query = "select * email_list";     $result = mysqli_query($dbc, $query) or die('error querying database.');     $mail = new phpmailer();     $mail->subject = $_post['subject'];     while ($row = mysqli_fetch_array($result)) {         $mail->addaddress($row["email"]);         $msg = "dear " . $row['first_name'] . " "              . $row['last_name'] . " "              . "\n" . $_post['elvismail'];         $mail->body = $msg;         $mail->send();         $mailer->clearallrecipients();         echo 'email sent to: ' . $row["email"] . '<br />';     }     mysqli_close($dbc); } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -