<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();
$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();
解决方案 »
- 请大侠指点,运行外部程序的问题
- PHP搜索结果分页显示的问题
- 存进mysql汉字全是乱码,php是utf-8,应该怎样设置啊?
- 帮忙转换3行代码,php转asp.
- 在网上找到的网站访问计数器是不是需要开一个服务器的选项才可以用?
- 为什么会出现这个参数??index.php?PHPSESSID=37a7c28646515ef399cff97f3d8b6296
- 谁有xajax库的压缩文件,发个地址啊.官方网站最近打不开
- php popen无法使用
- 如何解决 User jobs@ has already more than 'max_user_connections' active connections ?
- 是不是php也有权限问题?
- 广州工资问题
- apache 启动时提示 Unable to load dynamic library 'f:\php\php_iconv.dll' -'找不到指定程序
<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"> </td>
</tr>
<tr>
<td>收件人</td>------------------------------------收件人传给phpmailer我知道,数据表的邮件地址传给收件人怎么传
<td><input type="text" name="textfield2" /></td>
<td> </td>
</tr>
<tr>
<td>主题 </td>
<td><input type="text" name="textfield3" /></td>
<td> </td>
</tr>
<tr>
<td>邮件内容</td>
<td><input type="text" name="textfield4" /></td>
<td> </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>
将用户名和邮件地址,用分隔符隔开,当作checkbox的值,选中以后提交过去,在发送邮件之前,有一段程序根据传过来的数组构造AddMutieAddress的参数.还有什么不明白的吗?
我觉得我写的已经很清楚了.
<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>
<?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";
?>
<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>
$arrUser = $_POST['user'];
这样才成.就算查询数据库,你也可以构造你测试页哪样的html吧!
这不就是吗?
你能打印出来值吗?我下面这段程序是从一个数组来构造phpmailer的参数,这个是由值user;email来构成的.foreach($arrUser as $key=>$value)
{
$arrTemp = explode(";", $value);
$arrMailList[$arrTemp[1]] = $arrTemp[0];
}当然,如果你不想这么做,你就不能再用我这种方式本得到phpmailer的参数了.这个参数是这样构成的, $arrMailList[邮件地址] = "用户";
如果我这样说你还不是明白,哪你只能请求超级高手来帮助你实现这个功能了.
$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>
你的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'];
....
Message could not be sent.
Mailer Error: SMTP Error: The following recipients failed:
你的smtp服务器不行呀.
和程序无关!
其实好多,比如说smtp.sohu.com, 再找个sohu的用户名和密码.
finish
结帖吧.
应该是这样的吧.
忘记这个函数是我自己写的,还是原来就有的.
你怎么老是乱改我写好的代码呢.如果没有的话,可在phpmailer类里加上这个函数. function AddMutieAddress($arrAddress)
{
foreach($arrAddress as $key=>$value)
{
$this->AddAddress($key, $value);
}
}
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";
?>
这行去掉或者改成
var_dump($arrUser);
数组你也echo2 $arrTemp = explode(";", $value);
明明前面是用:号分开的,你非得用;去分隔
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.
<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>
<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";
?>
=>
<input type="checkbox" name="user[]" value='aaa:[email protected]'>
但是我先了多个,为啥只发送一个啊array(1) { [0]=> string(23) "aaaa:[email protected]" } Message has been sent
<input type="checkbox" name="user[]" value='aaaa:[email protected]'/>
</form>第一个后面,你就把这个form给关了.自己看着办吧.
从下面打印出来的结果可以看出,只发了第一个,第二个没发!array(1) { [0]=> string(23) "aaaa:[email protected]'" } Message has been sent 如果不只选第二个,不选第二个,就显示null,
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" />
http://topic.csdn.net/u/20110831/11/47b3e3a1-7d41-41ee-ba3f-912316ccb6f6.html
您好你能帮我看看 解决一下吗 也是phpmailer