dtvnbe1428 2014-06-14 15:38
浏览 20
已采纳

如何使用PHP同时从一个表发送电子邮件给2人

I'm getting trouble with my php code. I have a table named: prof_ales with 3 columns: cnp, evaluat and evaluator.

And a button "Send Email". When the client press the button I want to send an email to 2 specific email adresses which are already saved into my table "prof_ales" in the column "evaluator".

Here is my code, and for now it's working, but the message is send only at the last email adress.

    <input class="buttom" name="submit" id="submit" tabindex="5" value="Send Email" type="submit">  



<?php
if(isset($_POST['submit'])) {
$interogare = ("SELECT * FROM prof_ales  WHERE cnp='".$_SESSION['sess_user']."'");
$rezultat = mysql_query($interogare);
while ($rand = mysql_fetch_assoc($rezultat)) {
$ev= $rand['evaluat'];
$to = $rand['evaluator'];
}

$message = "test email ";
$subject = "Received from $ev"; 
$body = <<<EMAIL
 Etc etc

$message

Bla Bla 

EMAIL;

$header = "From: quabits.ro";
}
if($_POST){
mail($to, $subject, $body, $header);
echo "Sent";
}
?>  

As I said I want to send to both(or more) email adresses any time when button is pressed. Tks.

  • 写回答

2条回答 默认 最新

  • doumicheng6732 2014-06-14 16:19
    关注

    As already said above you need to put the call of the mail() function inside the while()-loop. Using correct formating makes the code easier to read:

    while ($rand = mysql_fetch_assoc($rezultat)) {
        $ev= $rand['evaluat'];
        $to = $rand['evaluator'];
        $message = "test email ";
        $subject = "Received from $ev"; 
        $body = "Test";
        $header = "From: quabits.ro";
        if($_POST) {
            mail($to, $subject, $body, $header);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路