473,721 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send multiple emails at once using php mail?

106 New Member
I want to send multiple emails from php with one unique script.
The emails are from a mysql database table.

How can I achieve this?
Aug 9 '10 #1
11 17734
Atli
5,058 Recognized Expert Expert
By using the mail() function.

All the information you could ever want on this subject is only a Google search away.
Aug 9 '10 #2
londres9b
106 New Member
I appreciate your help but either you didn't read what I posted or you ignored it..

I know how to use mail() function, I know how to send to multiple email addresses using mail() function.

But you didn't read the most important part - and it was in bold! -

The emails are from a mysql database table.


I need to retrieve the emails from the mysql table and then use the mail() function to send the emails.

How to do this?

P.S. Maybe should be on MySql topic...
Aug 9 '10 #3
Atli
5,058 Recognized Expert Expert
Retrieving the addresses from the MySQL database is fairly simple. You just need to build a SQL query that will select them all (a simple SELECT query should do, but I don't really know you database well enough to say that for sure), and use the mysql_query function to execute it. Then you just loop through the results and send an email for each one. (The manual has excellent examples that show how that works.)

And as you already know how to send an email, this should be fairly straight forward. If you run into any problems, post your code here and we will try to help solve them.

P.S.
If you are new to database interaction in PHP, it may be a good idea to read through a couple of tutorials. PHP and MySQL is probably one of the most written about software combo on the internet, so you should have no trouble finding something you like :)
Aug 9 '10 #4
londres9b
106 New Member
I know how to retrieve the emails but I don't know how to loop through them and email each one.. I've searched but haven't find nothing on this.
Aug 10 '10 #5
Atli
5,058 Recognized Expert Expert
Look at example #2 in the mysql_query entry in the manual. The lines inside the while loop is where you would put your mail() code.

If you change the SQL query in that example so that it gives you a list of email addresses, each iteration of the while loop will give you a new email address. You simply put the email code inside the loop and use the email address the loop provides.

Try it. If it doesn't work, post what you tried here and we will guide you through it.
Aug 10 '10 #6
agbb0cg
8 New Member
you should also sleep() the while for a couple of secs every 5/10 emails sent... ;)
Aug 10 '10 #7
Dormilich
8,658 Recognized Expert Moderator Expert
if you’re out for some more advanced code, some mail libraries also suport batch sending of emails (including the DB queries to get the data).
Aug 12 '10 #8
londres9b
106 New Member
Thanks! I got it!

@agbb0cg

I've looked at sleep() but how can I implement it on my script?
Aug 13 '10 #9
londres9b
106 New Member
Here's my code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //connect to database
  4.  
  5. $query = sprintf("SELECT * FROM mail");
  6.  
  7. $result = mysql_query($query);
  8.  
  9. while ($row = mysql_fetch_assoc($result)) {
  10.     $email = $row['Email'];
  11.     mail($email, 'My Subject', $message);
  12. }
  13. ?>
Aug 13 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

17
7641
by: rdemyan | last post by:
My app creates a building report. My users have requested that I provide functionality to e-mail these "building reports" to building managers once a month. So assuming that I have the following table that lists a building manager's name, e-mail address and their building, is there a way that I can automate this to send these monthly e-mails from Outlook. Ideally this would be a click one button type of action:
1
3989
by: Jeremy | last post by:
I have a table with user names and their balance. I am going to say there are 1000 people that need to get an email of their balance statement. I have one query that pulls the names and the corresponding balance. I have one report called BalanceReport. I need to send this report (for each different member) to their email. I would guess that I would need to loop through the member list, and also only run the query for the individual to...
10
3023
by: crazycooter | last post by:
I found an old thread on this (http://groups.google.com/group/alt.php/ browse_thread/thread/751edb9c723316c4/ea9bf92a9c6b807c?lnk=gst&q=mail() +duplicate&rnum=7#ea9bf92a9c6b807c), but there didnt seem to be a resolution. I also noticed that this was a pretty old thread and there didn't seem to be anything newer in the search results. Regardless, I have a very similar problem; I am consistently getting five emails per each PHP mail()...
5
11448
by: serena9131 | last post by:
Dear all, I having problem for sending subject in cheses language using mail(), Can anyone let me know how to send send non unicode subject ? Thanks Serena
2
2431
by: palanisiva | last post by:
Hi, I am using PHP mailer to send out 2 different emails. The problem I am having is only the first email is ever sent out. Below is my code. The first email $to but i add two mail id mail not sending. Please help....this is urgent! $mail = new PHPMailer(); $mail->From = "palani@xxxx.com"; $mail->FromName = " manager";
3
100069
digicrowd
by: digicrowd | last post by:
http://bytes.com/images/howtos/applemail_sig_icon.jpg You can make your emails fancy in Mail.app by using Rich Text formatting or even included Stationery. But, a simple way to send your own HTML creation (or any web page for that matter) is to use Safari. Follow these four easy steps. 1. Create the HTML Layout your HTML code including any images or graphics you'd like to include. In this example, we will make a simple birthday email to add...
5
3593
by: wktarin | last post by:
Hi. I'm a relative newcomer to the world of php, and I keep bumping into a problem with a mail () form. I need to send an automatic email to two addresses, but I can't seem to get it to work. One email address works just fine, but I can't get the email sent to two different addresses no matter what I try. Below is my code. If someone could help me spot my errors, I'd appreciate it. Thanks! Code from actual page: <?php //Check if the form...
1
1497
by: swetha123 | last post by:
hello, can any tell me how to send mails from site using mail() in php do we need to change in the php.ini these are in php.ini
1
7524
by: perhapscwk | last post by:
Below code works however it seems it will upload and save the attachment to server, how can send attachment without save the file into my server? and how to limit the file size to 3mb? $email = $_POST; $from = $_POST; $subject = $_POST; $message = $_POST; // Obtain file upload vars
0
1565
by: rserrador | last post by:
Hello. I'm creating a db in access 2007 and i want to have a buton on a report where i can send bcc multiple emails from a query. Can someone help me with the VBA code please.
0
8847
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8734
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9137
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9071
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6675
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4758
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3197
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2581
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.