I'm trying to send emails to multiple address pulled from SQL. I came up with following script but no luck. I know that using mail()
or sendmail
is not best choice, if anybody can point out where I went wrong or have a better solution using phpmailer that would be brilliant.
PS: I do not want to use SMTP as we are using an address that we will not be monitoring. The Do-NOT-REPLY one, actually we don't have email service at all. But server does support mail/sendmail/phpmailer, all tested.
<HTML>
<TITLE>Email Notification</TITLE>
<?php
include "subscribe/mySQL.class.php"; //Connect to SQL
if ($subject) {
$mailaddress = "DO-NOT-REPLY@domain.my";
$query = "select email from subscribe";
$res = mysql_query($query);
$row = mysql_fetch_array($res);
while ($row) {
mail($row['email'],$subject,$text."n ","From:".$mailaddress);
$row = mysql_fetch_array($res);
}
echo "<script type='text/javascript'>";
echo "parent.location.href='welcome.php'";
echo "</script>";}
?>
<BODY>
<P ALIGN=CENTER><FONT FACE="Arial" SIZE="7" COLOR="#FF0000">Send Notifications<BR><BR></FONT>
<P ALIGN=LEFT><FORM NAME="email" ACTION="test.php" METHOD="POST">
<FONT FACE="Arial" SIZE="6" COLOR="#0000FF">Subject:<INPUT TYPE=TEXT NAME="subject" SIZE="50" MAXLENGTH="18" value=<?php echo $subject ?>><BR><BR>
Content: <TEXTAREA NAME="text" COLS="90" ROWS="3" value="<?php echo $text?>"> </TEXTAREA><BR><BR>
</FONT>
<INPUT TYPE=SUBMIT VALUE=Send Email></FORM>
</BODY>
</HTML>