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
Post a Comment