用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楼
恩,刚刚实验过了
不加也可以,学习了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
