使用sql中的电子邮件向所有用户发送邮件
问题描述:
What I'm trying to do is this: I have a button that if clicked email will be sent to all customer in db that has email.
public function Email()
{
$ind_connect=$this->OpenDB();
$sql=mysql_query("SELECT `E-mail` FROM `orders`");
$num_rows=mysql_num_rows($sql);
$text ="Hi, How are you ?";
if($num_rows>0)
{
while($row = mysql_fetch_array($sql))
{
if(isset($row['E-mail']))
{
$tpl = file_get_contents("mail.eml");
$mail=$tpl;
$mail=strtr($mail,array(
"{TO}" =>$row['E-mail'],
"{TEXT}" =>$text,
));
list($head,$body) = preg_split("/?
?
/s",$mail,2);
echo "$head <br> $body <br>";
mail("","",$body,$head);
echo "<br>";
}
}
That's on the html file
Send Emails To Customers
<br><br><button name='SendEmail' button type='submit'>Click Here</button>
and this is calling to the func
if(isset($_POST['SendEmail']))
$db->Email();
答
You forgot to use correct HTML form
element with POST
method. Default the GET
method is using (according to http://www.w3schools.com/tags/att_form_method.asp).
Replace this part of your code
<br><br><button name='SendEmail' button type='submit'>Click Here</button>
with this
<form method="post">
<br><br><button type="submit" name="SendEmail">Click Here</form>
</form>