473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Send email to email addresses stored as variables

5 New Member
Hi,

I'm new to the forum and was wondering if anyone could help me!

Basically, I'm trying to create a script that will send an email to a group of recipients that are created elsewhere, plced in mysql database and then recalled and added as a variable to which the email is sent.

The problem I have is that I'm unsure how to get the email addresses from the database.

I've put a bit of code below. The idea is that the email addresses are taken from the db. This doesn't work. the email will go to the example address. How can I assign the email addresses from the db to individual variables?


Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM townfield"; 
  2. $result = mysql_query($query) or die(mysql_error());
  3. while($row = mysql_fetch_array($result)){
  4.     echo $row['email'];
  5.     echo "<br />";}
  6.  
  7.  
  8. if($fao == "1") {
  9. $attention = "All Staff";
  10. $recipients = $row['email'] . "," . "example@fixedaddress.com";}
Many thanks to anyone who could give me a hand with this!!
May 24 '09 #1
4 2118
bilibytes
128 New Member
I am not sure if I understood you but try this:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     $query = "SELECT * FROM townfield"; 
  3.     $result = mysql_query($query) or die(mysql_error());
  4.     while($row = mysql_fetch_array($result)){
  5.         $emailsArray[] = $row['email'];
  6.     }
  7.  
  8.     $recipients = implode(', ', $emailsArray);//output emai@fdf.com, email@fa.com, eamil@sdf.com...
  9. }
  10.  
or within the loop:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     $query = "SELECT * FROM townfield"; 
  3.     $result = mysql_query($query) or die(mysql_error());
  4.     $recipients = '';
  5.     while($row = mysql_fetch_array($result)){
  6.         $recipients .= $row['email'] . ', ';
  7.     }
  8.     //subtract the last ', '
  9.      $recipients = substr($recipients, -2);
  10.  
that's it, don't know which is faster..

Hope it helps,
Cheers

Bilibytes
May 24 '09 #2
renegade78
5 New Member
Thanks, I'll give it a go!

Much appreciated!
May 24 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
Swiftmailer offers a method to send emails as batch
May 24 '09 #4
renegade78
5 New Member
First one worked a treat! Thanks a lot.
May 24 '09 #5

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

Similar topics

0
2932
by: cooldv | last post by:
i have an *access database + ASP newsletter* that is working fine and it sends newsletter to ALL the email addresses in the DB. i want to send this newsletter to only a select group (like people...
6
11162
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
1
5319
by: Jay McGrath | last post by:
Help - trying to send a simple text email with with as little user intervention. I am trying to create a button in my Access application that will automatically send a simple text email. It...
11
5013
by: Tim Smallwood | last post by:
Hi, I have an Access project that I use to allow a client to hit an SQL server at my host. This project has several forms that are used to udpate tables, etc, but I'd also like to be able to...
3
1800
by: Nathan Sokalski | last post by:
I have an ASP.NET page that sends a Mail.MailMessage to several email addresses (all mine). However, one of the addresses, the one ending in @verizon.net, does not seem to be recieving the message...
1
2309
by: divya | last post by:
I have a form which has a textarea,name - txtTo where he adds email addresses.Now when he clicks on sendemail I want to open a mailto link with addresses taken from textarea. Example I added...
5
2146
by: Mike | last post by:
I have a page with a textbox that a user can enter in mutliple email addresses such as: user1@yahoo.com;user2@yahoo.com;user3@gmail.com; and so on, I then have a foreach loop to get all of the...
4
1987
by: chris | last post by:
I need to maintain a list of subscribers to an email list for a "newsletter" that will be sent via a web form probably once a month. I anticipate low numbers--tens to maybe one hundred subscribers...
1
6533
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
0
7199
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,...
0
7074
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...
0
7273
Oralloy
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,...
1
6982
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...
0
7451
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...
1
5000
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...
0
1501
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 ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
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...

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.