用phpmailer如何群发邮件
csdn的版主们不好意思又来麻烦你们了
请问我数据库里面比如有10条email的地址,我如何得到他,然后按钮提交群发出去
就根据昨天我问的帖子
http://bbs.csdn.net/topics/390967296?page=1#post-398769890
库名email,表名bl_email,字段email
回复讨论(解决方案)
简单说一下2个方法,可试试看有问题再讨论
1. 你上一个帖子提到的用2页处理
从 A.php 获取10条email资料 (select email from bl_email where ..... )
然後sumit表单POST到B.php处理寄送动作
2. 用ajax不换页处理
从 A.php 获取10条email资料 (select email from bl_email where ..... )
按下按钮後用ajax post 10条email到後端 B.php处理寄送动作
回复1楼
为何只读取到一条记录
$conn=mysql_connect("localhost","root","");//连接数据库
mysql_select_db("email",$conn);//连接哪个库
mysql_query("set names utf-8");//编码方式
$sql="select * from bl_email";//查询那个表
$result=mysql_query($sql,$conn);
while($array=mysql_fetch_array($result)){
$email=$array["address"];
};
print_r("$email");
?>
回复1楼
为何只读取到一条记录
$conn=mysql_connect("localhost","root","");//连接数据库
mysql_select_db("email",$conn);//连接哪个库
mysql_query("set names utf-8");//编码方式
$sql="select * from bl_email";//查询那个表
$result=mysql_query($sql,$conn);
while($array=mysql_fetch_array($result)){
$email=$array["address"];
};
print_r("$email");
?>
用这句看看印出什麽结果
print_r(mysql_fetch_array($result));
难道错误在这句吗
打印的结果
Array ( [0] => 2 [id] => 2 [1] => tom [name] => tom [2] => hzhhzw123@126.com [address] => hzhhzw123@126.com [3] => 2345 [tel] => 2345 )
回复3楼
前面没看,4楼的打印是没加while的
加了while的
打印出 mysql_fetch_array(Resource id #4)
这样看来你提取的数据的确只有一行,你确定数据库内有多笔资料?
回复3楼
问题找到了,打印没有放在while里面
恭喜你..
那怎么送到表单去
我直接把上面取得变量$email加到了这个上面
$mail->AddAddress("$email","h"); //添加收件人
这样可以提交,就是邮件发不过去
我直接把上面取得变量$email加到了这个上面
$mail->AddAddress("$email","h"); //添加收件人
这样可以提交,就是邮件发不过去
$mail->AddAddress("$email","h");
改为
foreach($email as $em){
$mail->AddAddress("$em","h");
}
我直接把上面取得变量$email加到了这个上面
$mail->AddAddress("$email","h"); //添加收件人
这样可以提交,就是邮件发不过去
if(!$mail->Send()) {
echo "发送失败: " . $mail->ErrorInfo;
}
回复11楼和12楼
提示:You must provide at least one recipient email address.
为什么没有获得地址
程序
$conn=mysql_connect("localhost","root","");//连接数据库
mysql_select_db("email",$conn);//连接哪个库
mysql_query("set names utf-8");//编码方式
$sql="select * from bl_email";//查询那个表
$result=mysql_query($sql,$conn);
while($array=mysql_fetch_array($result))
{
$email=$array["address"];
}
if(is_array($email))
{
foreach($email as $em)
{
$mail->AddAddress("$em","h");
}
}
if(!$mail->Send()){
echo "发送失败: " . $mail->ErrorInfo;
?>
<script> <br /> alert('无法发送邮件,错误信息:'.$mail->ErrorInfo); <br /> window.location = 'send.php'; <br /> </script>
} else {
//echo "邮件已经发送";
?>
<script> <br /> alert('邮件发送成功'); <br /> window.location = 'send.php'; <br /> </script>
}
?>
if(is_array($email))
如果$email不是array的情?,你?有?。
问题已经解决
在while上面给$email定义一个空的数组
就解决了
前面应该问题是在
打印在while里面可以出来多个值
在外部打印就只出来一个值
然后下面的$mail->AddAddress("$em","h");在按照版主的加个foreach循环
就可以群发了
请教下楼主,你所说的 在while上面给$email定义一个空的数组
是下面这样吗?
我也是新手。。。
while($array=mysql_fetch_array($result))
{
$email[]=$array["address"];
}
回复16楼
我是这样做的
$email=array();
while($row=mysql_fetch_array($result))
{
$email[]=$row["address"];
}
while之前的数组应该不用定义吧?
$email[]会自动创建一个数组。
回复18楼
恩,刚刚实验过了
不加也可以,学习了

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

11 beste PHP -URL -Shortener -Skripte (kostenlos und Premium)

Arbeiten mit Flash -Sitzungsdaten in Laravel

Erstellen Sie eine React -App mit einem Laravel -Back -Ende: Teil 2, reagieren

Vereinfachte HTTP -Reaktion verspottet in Laravel -Tests

Curl in PHP: So verwenden Sie die PHP -Curl -Erweiterung in REST -APIs

12 Beste PHP -Chat -Skripte auf Codecanyon

Ankündigung von 2025 PHP Situation Survey
