473,883 Members | 1,709 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 17756
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
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
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.

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
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
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
8 New Member
you should also sleep() the while for a couple of secs every 5/10 emails sent... ;)
Aug 10 '10 #7
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
106 New Member
Thanks! I got it!


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

Expand|Select|Wrap|Line Numbers
  1. <?php
  3. //connect to database
  5. $query = sprintf("SELECT * FROM mail");
  7. $result = mysql_query($query);
  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

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:
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...
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()...
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
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";
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...
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...
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
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
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.
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...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.