<input type='checkbox' name='user[]' value='username:[email protected]'>
 
 $arrUser = $_POST['user']; require_once("include/class.phpmailer.php");
 $mail = new PHPMailer();
 //设置mail参数
 ...
 $mail->IsSendmail();
 $mail->IsHtml(true); foreach($arrUser as $key=>$value)
 {
   $arrTemp = explode(":", $value);
   $arrMailList[$arrTemp[1]] = $arrTemp[0];
 } $mail->AddMutieAddress($arrMailList);
 $mail->send();

解决方案 »

  1.   

    <input type='checkbox' name='user[]' value='username:[email protected]'> 收件人传给phpmailer我知道,数据表的邮件地址传给收件人怎么传phpwebmail的界面<table width="379" border="1" cellpadding="0" cellspacing="0">
      <tr>
        <td width="69">发件人</td>
        <td width="205"><form id="form1" name="form1" method="post" action="">
          <label>
          <input type="text" name="textfield" />
            </label>
        </form>
        </td>
        <td width="83">&nbsp;</td>
      </tr>
      <tr>
        <td>收件人</td>------------------------------------收件人传给phpmailer我知道,数据表的邮件地址传给收件人怎么传
        <td><input type="text" name="textfield2" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>主题 </td>
        <td><input type="text" name="textfield3" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>邮件内容</td>
        <td><input type="text" name="textfield4" /></td>
        <td>&nbsp;</td>
      </tr>
    </table>数据库姓名,邮件列表
    <table width="333" border="1">
      <tr>
        <td>全选</td>
        <td>姓名</td>
        <td>地址</td>
      </tr>
      <tr>
        <td><form id="form2" name="form2" method="post" action="">
          <input type="checkbox" name="checkbox" value="checkbox" />
        </form>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="checkbox2" value="checkbox" /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table>
      

  2.   

    仔细看回帖.
    将用户名和邮件地址,用分隔符隔开,当作checkbox的值,选中以后提交过去,在发送邮件之前,有一段程序根据传过来的数组构造AddMutieAddress的参数.还有什么不明白的吗?
    我觉得我写的已经很清楚了.
      

  3.   


    <tr>
        <td><form id="form2" name="form2" method="post" action="">
          <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbbb:[email protected]' /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
      

  4.   

    首先非常感谢你,但你的那个报错,Warning: Invalid argument supplied for foreach() in C:\aabb\htdocs\phpmailer\send.php on line 23Fatal error: Call to undefined method PHPMailer::AddMutieAddress() in C:\aabb\htdocs\phpmailer\send.php on line 29send.php
    <?php
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $arrUser = $_POST['address'];
    $title = $_POST['title'];
    $content = $_POST['content'];
    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "mail.aa.cn"; // specify main and backup server
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "bb"; // SMTP username
    $mail->Password = "password"; // SMTP password$mail->From = "[email protected]";
    $mail->FromName = "aa";
    //$mail->AddAddress("$address", "");
    //$mail->AddAddress(""); // name is optional
    //$mail->AddReplyTo("", "");//$mail->WordWrap = 50; // set word wrap to 50 characters
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
    $mail->IsHTML(true); // set email format to HTML
    foreach($arrUser as $key=>$value)
     {
       $arrTemp = explode(";", $value);
       $arrMailList[$arrTemp[1]] = $arrTemp[0];
     } $mail->AddMutieAddress($arrMailList);$mail->Subject = "$title";
    $mail->Body = "$content";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";if(!$mail->Send())
    {
     echo "Message could not be sent. <p>";
     echo "Mailer Error: " . $mail->ErrorInfo;
     exit;
    }echo "Message has been sent";
    ?>
      

  5.   

    <html>
    <body>
    <h3>phpmailer Test</h3><form name="phpmailer" action="send.php" method="post">
    <input type="hidden" name="submitted" value="1"/>
    addre: <input type="text" size="50" name="address" /><br>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
    <br/>
    <input type="submit" value="发送"/>
    </form><table border=1>-----------//这只是个测试,以后是要查询数据库
    <tr>
        <td><form id="form2" name="form2" method="post" action="">
          <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbbb:[email protected]' /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table></body>
    </html>
      

  6.   

    出错是因为你没有
    $arrUser = $_POST['user'];
    这样才成.就算查询数据库,你也可以构造你测试页哪样的html吧!
      

  7.   

    $arrUser = $_POST['address'];
    这不就是吗?
      

  8.   

    用phpmyadmin把邮件地址的表导出成excel,让后吧邮件地址拷贝出来,放到文本文件里,在用邮件群发工具发,很快的
      

  9.   

    朋友,你的address这个在哪呢?你去哪找呀?
    你能打印出来值吗?我下面这段程序是从一个数组来构造phpmailer的参数,这个是由值user;email来构成的.foreach($arrUser as $key=>$value)
     {
       $arrTemp = explode(";", $value);
       $arrMailList[$arrTemp[1]] = $arrTemp[0];
     }当然,如果你不想这么做,你就不能再用我这种方式本得到phpmailer的参数了.这个参数是这样构成的, $arrMailList[邮件地址] = "用户";
    如果我这样说你还不是明白,哪你只能请求超级高手来帮助你实现这个功能了.
      

  10.   


    $arrUser = $_POST['address']; 我手填入就可以打出来值,虽然能打出来,但是还是报错[email protected]
    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\phpmailer\send.php on line 26
    Message could not be sent. 
    Mailer Error: SMTP Error: The following recipients failed: 选择checkbox就不行,打不出来值!
    send.php
    <?php
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $arrUser = $_POST['address'];
    $title = $_POST['title'];
    $content = $_POST['content'];
    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "mail.aa.cn"; // specify main and backup server
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "bb"; // SMTP username
    $mail->Password = "password"; // SMTP password$mail->From = "[email protected]";
    $mail->FromName = "aa";
    //$mail->AddAddress("$address", "");
    //$mail->AddAddress(""); // name is optional
    //$mail->AddReplyTo("", "");//$mail->WordWrap = 50; // set word wrap to 50 characters
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
    $mail->IsHTML(true); // set email format to HTMLecho"$arruser"    //   打出用户邮件名foreach($arrUser as $key=>$value)
     {
       $arrTemp = explode(";", $value);
       $arrMailList[$arrTemp[1]] = $arrTemp[0];
     } $mail->AddAddress($arrMailList);$mail->Subject = "$title";
    $mail->Body = "$content";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";if(!$mail->Send())
    {
     echo "Message could not be sent. <p>";
     echo "Mailer Error: " . $mail->ErrorInfo;
     exit;
    }echo "Message has been sent";
    ?>
    test.php
    <html>
    <body>
    <h3>phpmailer Test</h3><form name="phpmailer" action="send.php" method="post">
    <input type="hidden" name="submitted" value="1"/>addre: <input type="text" size="50" name="user" /><br>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
    <br/>
    <input type="submit" value="发送"/>
    </form><table border=1><!---//这只是个测试,以后是要查询数据库--->
    <tr>
        <td>
          <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbbb:[email protected]' /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table></body>
    </html>
      

  11.   

    $arrUser = $_POST['address'];
    你的html里form里有address吗???
    其实你根本没有理解我的思路代码都给你改出来了,你非得自己改成错误的,无语.下面的代码你再试试.
    只要选中checkbox,提交以后,肯定就可以了.<html>
    <body>
    <h3>phpmailer Test</h3><form name="phpmailer" action="send.php" method="post">
    <input type="hidden" name="submitted" value="1"/>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
    <br/>
    <input type="submit" value="发送"/>
    <table border=1><!---//这只是个测试,以后是要查询数据库--->
    <tr>
        <td>
          <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbbb:[email protected]' /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    <?php
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    //为什么要改我这句关键的值.
    $arrUser = $_POST['user'];
    ....
      

  12.   

    非常感谢,但还是不行,打出值及错误如下,完全照你的方法做的Array
    Message could not be sent. 
    Mailer Error: SMTP Error: The following recipients failed: 
      

  13.   

    这就是你配置的问题
    你的smtp服务器不行呀.
    和程序无关!
      

  14.   

    不会叫我给你一个正确的smtp发送服务器配置吧.
    其实好多,比如说smtp.sohu.com, 再找个sohu的用户名和密码.
    finish
    结帖吧.
      

  15.   

    邮件服务器应该没问题啊,我自己架的,用outlook 都可以发送,或抄送多具列表文件啊不应该是邮件服务器问题,为什么数组打印出来是:Array ,而不是具体地址?
      

  16.   

    难道是phpmailer不支持 列表发送??
      

  17.   

    $mail->AddMutieAddress($arrMailList);
    应该是这样的吧.
    忘记这个函数是我自己写的,还是原来就有的.
    你怎么老是乱改我写好的代码呢.如果没有的话,可在phpmailer类里加上这个函数.    function AddMutieAddress($arrAddress)
        {
          foreach($arrAddress as $key=>$value)
          {
            $this->AddAddress($key, $value);
          }
        }
      

  18.   

    哈哈,别怒哈!可能是没了解清楚吧!我再整理一下哈,加分没问题啦,但是这样照你的方法还是有错!Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\phpmailer\send.php on line 27    //-------这是加在send.php中的foreach错误Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\phpmailer\class.phpmailer.php on line 334   //--------这是加在phpmailer类class.phpmailer.php的AddMutieAddress函数的那行错误。函数有错??
    Message could not be sent. 
    Mailer Error: You must provide at least one recipient email address.在class.phpmailer.php加上:   public function AddMutieAddress($arrAddress)     --------这类里面都要加上public
        {
          foreach($arrAddress as $key=>$value)
          {
            $this->AddAddress($key, $value);
          }
        }test.php
    <html>
    <body>
    <h3>phpmailer Test</h3><form name="phpmailer" action="send.php" method="post">
    <input type="hidden" name="submitted" value="1"/>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
    <br/>
    <input type="submit" value="发送"/>
    <table border=1><!---//这只是个测试,以后是要查询数据库--->
    <tr>
        <td>
          <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbbb:[email protected]' /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table>
    </form>
    </body>
    </html>send.php
    <?php
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $arrUser = $_POST['user'];       //这是获取checkbox的数组吧
    $title = $_POST['title'];
    $content = $_POST['content'];
    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "mail.aa.cn"; // specify main and backup server
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "bb"; // SMTP username
    $mail->Password = "password"; // SMTP password$mail->From = "[email protected]";
    $mail->FromName = "aa";
    //$mail->AddAddress("$address", "");
    //$mail->AddAddress(""); // name is optional
    //$mail->AddReplyTo("", "");//$mail->WordWrap = 50; // set word wrap to 50 characters
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
    $mail->IsHTML(true); // set email format to HTMLecho"$arruser"    //   打出用户邮件名foreach($arrUser as $key=>$value)                          //这报错哦,看上面
     {
       $arrTemp = explode(";", $value);
       $arrMailList[$arrTemp[1]] = $arrTemp[0];
     } $mail->AddMutieAddress($arrMailList);    //-----------这是你说要改的地方吧$mail->Subject = "$title";
    $mail->Body = "$content";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";if(!$mail->Send())
    {
     echo "Message could not be sent. <p>";
     echo "Mailer Error: " . $mail->ErrorInfo;
     exit;
    }echo "Message has been sent";
    ?>
      

  19.   

    1 echo"$arruser"    //   打出用户邮件名
    这行去掉或者改成
    var_dump($arrUser);
    数组你也echo2 $arrTemp = explode(";", $value);
    明明前面是用:号分开的,你非得用;去分隔
      

  20.   

    传过来是空NULL 
    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\phpmailer\send.php on line 27Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\phpmailer\class.phpmailer.php on line 334
    Message could not be sent.
      

  21.   


    <form name="phpmailer" action="send.php" method="post">
    <input type="hidden" name="submitted" value="1"/>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
    <br/>
    <input type="submit" value="发送"/>
    看看???号哪行,多个</form>
    <table border=1><!---//这只是个测试,以后是要查询数据库--->
    <tr>
        <td>
          <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>?????????????????????????????????????????????????
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbbb:[email protected]' /></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table>
    </form>
      

  22.   

    注意我的phpmailer是1.6的.
    <html>
    <body>
    <h3>phpmailer Test</h3><form name="phpmailer" action="send.php" method="post">
    <input type="hidden" name="submitted" value="1"/>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
    <br/>
    <input type="submit" value="发送"/><table border=1><!---//这只是个测试,以后是要查询数据库--->
    <tr>
        <td>
          <input type="checkbox" name="user[0]"  value='aaa:[email protected]'>
        </td>
        <td>aaaa</td>
        <td>[email protected]</td>
      </tr>
      <tr>
        <td><input type="checkbox" name="user[]"  value='bbb:[email protected]'></td>
        <td>bbbb</td>
        <td>[email protected]</td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    <?php
    error_reporting(E_ALL);
    require("class.phpmailer.php");
    $mail = new PHPMailer();
    $arrUser = $_POST['user'];       //这是获取checkbox的数组吧
    $title = $_POST['title'];
    $content = $_POST['content'];
    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "mail.aa.cn"; // specify main and backup server
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "bb"; // SMTP username
    $mail->Password = "password"; // SMTP password$mail->From = "[email protected]";
    $mail->FromName = "aa";
    //$mail->AddAddress("$address", "");
    //$mail->AddAddress(""); // name is optional
    //$mail->AddReplyTo("", "");//$mail->WordWrap = 50; // set word wrap to 50 characters
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
    $mail->IsHTML(true); // set email format to HTMLvar_dump($arrUser);    //   打出用户邮件名foreach($arrUser as $key=>$value)                          //这报错哦,看上面
     {
       $arrTemp = explode(":", $value);
       $arrMailList[$arrTemp[1]] = $arrTemp[0];
     }
     var_dump($arrMailList);
     $mail->AddMutieAddress($arrMailList);    //-----------这是你说要改的地方吧$mail->Subject = "$title";
    $mail->Body = "$content";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";if(!$mail->Send())
    {
     echo "Message could not be sent. <p>";
     echo "Mailer Error: " . $mail->ErrorInfo;
     exit;
    }echo "Message has been sent";
    ?>
      

  23.   

    <input type="checkbox" name="user[0]"  value='aaa:[email protected]'>
    =>
    <input type="checkbox" name="user[]"  value='aaa:[email protected]'>
      

  24.   

    调了一下,是数组注释了
    但是我先了多个,为啥只发送一个啊array(1) { [0]=> string(23) "aaaa:[email protected]" } Message has been sent
      

  25.   


    <input type="checkbox" name="user[]"  value='aaaa:[email protected]'/>
        </form>第一个后面,你就把这个form给关了.自己看着办吧.
      

  26.   

    两个都选中:
    从下面打印出来的结果可以看出,只发了第一个,第二个没发!array(1) { [0]=> string(23) "aaaa:[email protected]'" } Message has been sent 如果不只选第二个,不选第二个,就显示null,
      

  27.   

    非常非常的感谢!终于通了!确实太粗心了,呵呵!另外有没有办法,手动填写email地址,加上checkbox选的一起发送!!
    email: <input type="text" size="50" name="user" /><br>
    titie: <input type="text" size="50" name="title" /><br>
    content: <input type="text" size="50" name="content" />
      

  28.   

    jakey9826  你真是太负责了
      

  29.   


    http://topic.csdn.net/u/20110831/11/47b3e3a1-7d41-41ee-ba3f-912316ccb6f6.html
    您好你能帮我看看 解决一下吗    也是phpmailer