dongruyan4948 2016-07-11 16:11
浏览 65
已采纳

使用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();
  • 写回答

1条回答 默认 最新

  • douxiuyi6529 2016-07-11 18:04
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi