How to send mails in a group using phpmailer

Source: Internet
Author: User
How can I send emails to csdn moderators using phpmailer? sorry, I am bothering you again.

Could you tell me how I can get 10 email addresses in my database, and then click the button to submit them to the group?
Based on the post I asked yesterday
Http://bbs.csdn.net/topics/390967296? Page = 1 # post-398769890
Database name email, table name bl_email, field email


Reply to discussion (solution)

Let's briefly describe two methods. try again and discuss the problem.

1. You mentioned in the previous post processed on two pages.
Obtain 10 email records from A. php (select email from bl_email where .....)
Then the sumit form is POST to B. php to process the sending action.

2. do not change pages with ajax
Obtain 10 email records from A. php (select email from bl_email where .....)
Press the button and use ajax post to send 10 emails to the backend B. php for sending.

Reply to floor 1
Why read-only access to a record
$ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("email", $ conn); // database to which the database is connected
Mysql_query ("set names UTF-8"); // encoding method
$ SQL = "select * from bl_email"; // query the table
$ Result = mysql_query ($ SQL, $ conn );
While ($ array = mysql_fetch_array ($ result )){
$ Email = $ array ["address"];
};
Print_r ("$ email ");
?>

Reply to floor 1
Why read-only access to a record
$ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("email", $ conn); // database to which the database is connected
Mysql_query ("set names UTF-8"); // encoding method
$ SQL = "select * from bl_email"; // query the table
$ Result = mysql_query ($ SQL, $ conn );
While ($ array = mysql_fetch_array ($ result )){
$ Email = $ array ["address"];
};
Print_r ("$ email ");
?>



Use this sentence to check the printed result.
Print_r (mysql_fetch_array ($ result ));

Is the error true?
Printed result
Array ([0] => 2 [id] => 2 [1] => tom [name] => tom [2] => hzhhzw123@126.com [address] => hzhhzw123@126.com [3] => 2345 [tel] => 2345)

Reply to third floor
I didn't see it before. I didn't add while to the print on the fourth floor.
Added while
Print mysql_fetch_array (Resource id #4)

In this case, the data you extracted is indeed only one row. Are you sure there are multiple pieces of data in the database?

Reply to third floor
The problem is found, and the print is not placed in the while

Congratulations ..

How can I send it to the form?

I directly added the above variable $ email to the above
$ Mail-> AddAddress ("$ email", "h"); // add a recipient
In this way, the email cannot be sent.

I directly added the above variable $ email to the above
$ Mail-> AddAddress ("$ email", "h"); // add a recipient
In this way, the email cannot be sent.



$ Mail-> AddAddress ("$ email", "h ");
Change
Foreach ($ email as $ em ){
$ Mail-> AddAddress ("$ em", "h ");
}

I directly added the above variable $ email to the above
$ Mail-> AddAddress ("$ email", "h"); // add a recipient
In this way, the email cannot be sent.



If (! $ Mail-> Send ()){
Echo "failed to send:". $ mail-> ErrorInfo;
}

Reply to 11 and 12 floors
Tip: You must provide at least one recipient email address.
Why didn't I get the address?
Program
$ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
Mysql_select_db ("email", $ conn); // database to which the database is connected
Mysql_query ("set names UTF-8"); // encoding method
$ SQL = "select * from bl_email"; // query the table
$ 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 "failed to send:". $ mail-> ErrorInfo;
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.