473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

PHP Array from SQL Database

10
What im attempting to do is pull email address from a database already built, i need to be able to select the email address depending on the date they are given.

Then i need to be able to Implode the list of email address so i can send out multiple emails to multiple Clients at one time. This is what i have so far.


******************Form Application****************

<select name="emailto" size="15" multiple id="emailto" style="color: #000000; font-size: 8pt; font-family: Verdana" tabindex="">

<?php
$users_sql = "SELECT * FROM ******* WHERE site_tag = '*****' AND date_received BETWEEN '" . $_POST["startDate"] . "' AND '" . $_POST["endDate"] . "'";
$users_result = @mysql_query($users_sql);
while($users = @mysql_fetch_array($users_result))

{
echo "<option";

echo">" . $users["email"] ;
echo",</option>\n";

}

?>
</select>

**************************
**************************php code*********************

if($_POST['email_now'])
{

$to = $_POST['emailto'];
$from = "***************";
$subject = "*******************";
$headers .= ''***************".$eol;
$headers .= '**************'.$eol;
$headers .= 'Return-Path: '.$eol; // these two to set reply address
$headers .= "Message-ID: <".$subject.">".$eol;
//$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
$body= $_POST['edited'];
//EOF;

$success = mail($to, $subject, $body, $headers);

if ($success)
{
$msg="";
mass_email($msg);


}
else
{
$msg=".";
mass_email($msg);

}
}

But what i need it to do is when i select or whoever i select from that form and click Email, it emails all of them. and i cant figure out for the life of me what im doing wrong.
Jan 10 '08 #1
13 5979
ak1dnar
1,584 Expert 1GB
Could you please tell us,what is NOT working in this script?
Please USE CODE tags in future.
Jan 10 '08 #2
border9
10
Its not allowing me to send to the email address the Form brings up. Right now i have it pulling about 15 email addresses from the Database and its not sending to them only one.
Jan 10 '08 #3
ak1dnar
1,584 Expert 1GB
Print your emails in the list menu like this: set the name attribute in this way emailto[]

Expand|Select|Wrap|Line Numbers
  1. <select name="emailto[]" multiple="MULTIPLE" id="emailto[]">
  2.   <option value="1@domain.com">1@domain.com</option>
  3.   <option value="2@domain.com">2@domain.com</option>
  4.   <option value="3@domain.com">3@domain.com</option>
  5. </select>
On server page
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $toArray = $_POST['emailto'];
  3. $explodedString = implode(",",$toArray);
  4. echo $explodedString;
  5. ?>

Outputs:
Expand|Select|Wrap|Line Numbers
  1. 1@domain.com,2@domain.com,3@domain.com
Pass the $explodedString to the mail() function.
Jan 10 '08 #4
border9
10
Print your emails in the list menu like this: set the name attribute in this way emailto[]

Expand|Select|Wrap|Line Numbers
  1. <select name="emailto[]" multiple="MULTIPLE" id="emailto[]">
  2.   <option value="1@domain.com">1@domain.com</option>
  3.   <option value="2@domain.com">2@domain.com</option>
  4.   <option value="3@domain.com">3@domain.com</option>
  5. </select>
On server page
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $toArray = $_POST['emailto'];
  3. $explodedString = implode(",",$toArray);
  4. echo $explodedString;
  5. ?>

Outputs:
Expand|Select|Wrap|Line Numbers
  1. 1@domain.com,2@domain.com,3@domain.com
Pass the $explodedString to the mail() function.
I see where your going with that, But i need to pull the emails from the database, they arent emails i put in myself. That Form is built off email address from the mySQL Database. How do i create the array from the emails in the database?
Jan 10 '08 #5
border9
10
Anyone have any idea what im trying to attempt here or what i have to do to make it work?

If you can help please by all means i would greatly appricate it. Thanks
Jan 11 '08 #6
ak1dnar
1,584 Expert 1GB
Oh you want to build the List menu right?
Sorry I don't have a Email Database with me, So I'm using one of my existing database.

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. @mysql_connect("localhost","root","dba")or die(mysql_error());
  3. @mysql_select_db("my_store")or die(mysql_error());
  4. $result = mysql_query("SELECT p_name from products");
  5. while($row=mysql_fetch_array($result)){
  6. $options .= '<option value="'.$row['p_name'].'">'.$row['p_name'].'</option>';
  7. }
  8. ?>
  9. <html>
  10. <body>
  11. <form action="index.php" method="post">
  12. <select name="emailto[]" multiple="MULTIPLE" id="emailto[]">
  13. <?php echo $options ?>
  14. </select>
  15. <input type="submit" name="Submit" value="Submit" />
  16. </form>
  17. </body>
  18. </html>
  19.  
Jan 11 '08 #7
border9
10
Ok, so that builds the menu, how do i take whats in that menu and email all of the clients that are brought up in that menu?

I need to be able to Click iether 1 or 20 of those items in that menu and be able to email the. Any ideas?
Jan 11 '08 #8
border9
10
[PHP]
<?php
if($_POST['email_now'])
{

$to = $_POST['emailto'];
$from = "";
$subject = "";
$headers .= "".$eol;
$headers .= "".$eol;
$headers .= 'Return-Path: '.$eol; // these two to set reply address
$headers .= "Message-ID: <".$subject.">".$eol;
//$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
$body= $_POST['edited'];
//EOF;

$success = mail($to, $subject, $body, $headers);

if ($success)
{
$msg="";
mass_email($msg);


}
else
{
$msg=".";
mass_email($msg);

}
}
?>
[/PHP]

I need this code to be able to read iether 1 or multiple selections for the List that is created from the database. What i need it to do is Send out an Email to any Selected Items from that list.
Jan 12 '08 #9
border9
10
Can anyone see what im trying to acomplish here?
Jan 15 '08 #10
ak1dnar
1,584 Expert 1GB
Ok, so that builds the menu, how do i take whats in that menu and email all of the clients that are brought up in that menu?

I need to be able to Click iether 1 or 20 of those items in that menu and be able to email the. Any ideas?
The code snippet that I've posted here will build the list menu. Then What you have to do, Select the recipient from that List (You can select 1 or more email addresses ) and submit those addresses to the php script which sends the mail. If you want to send the mail with out any user interaction WHY you need this LIST MENU, just pass the emails to the mail() function.
Jan 15 '08 #11
border9
10
The code snippet that I've posted here will build the list menu. Then What you have to do, Select the recipient from that List (You can select 1 or more email addresses ) and submit those addresses to the php script which sends the mail. If you want to send the mail with out any user interaction WHY you need this LIST MENU, just pass the emails to the mail() function.
Mainly i want the USER to be able to Select AS many AS theyd like to email one email to. OR if they would like to email them all. Im trying to get the code you gave me working right know, ill let you know if that was what i was looking for. Thank you.
Jan 15 '08 #12
border9
10
Ok, it seems to be kind of working, my next question would be how do i strip out duplicate email address? thanks
Jan 15 '08 #13
border9
10
[PHP]emailto[][/PHP]

Im confused how do i make the php Email call this command?

[PHP]if($_POST['email_now'])
{

$to = emailto[];
$from = "";
$subject = "" .$quote;
$headers .= ''.$eol;
$headers .= ''.$eol;
$headers .= ''.$eol;
$headers .= "Message-ID: <".$subject.">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
$body= $_POST['edited'];
//EOF;
$success = mail($to, $subject, $body, $headers);

if ($success)
{
$msg="";
mass_email($msg);


}
else
{
$msg="";
mass_email($msg);

}
}[/PHP]
I dont follow how i make this code call the List that you made it produce?
Jan 15 '08 #14

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

Similar topics

12
by: James | last post by:
Hi, Have posted before, but will simplify problem here. For original post go to http://forums.devshed.com/t80025/s.html I have setup 2 arrays like so in my one page script: $carers =...
5
by: Joel Farris | last post by:
I've just finished reading Kevin Yank's book "Build Your Own Database Driven Website", and I've not quite got a handle on the array variable. Why do I need an array? Give me an example of an...
4
by: John Hoge | last post by:
I'm looking to make an admin page for a web photo gallery, and I need to make a drop down menu showing all files in a given directory that do not have comments in a database for the given filename....
23
by: Rob Meade | last post by:
Lo all, Ok - this is what I was aiming to do, and then I thought - naahhh, that cant be right! query database results to recordset results to array using GetRows update values in one column...
0
by: EMiller | last post by:
Hello, I am encountering a development challenge here that seems to be stumping me. I am developing a C#/.NET application using an MSDE database. There is a particular field in a table that I...
1
by: garimapuri | last post by:
hi ihad an array in php and iwant to insert its value in database the coding is: <?php $nv_pairs = explode('&',$query_string); $array; list ($name, $value) = explode ('=',$nv_pairs); $i = 0;...
4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
2
by: assgar | last post by:
I am having problems getting the user selected form info to inserted into the mysql database. I am also rec eving an error: Warning: Variable passed to each() is not an array or object in ...
5
by: jmDesktop | last post by:
In my code I cannot figure out how to retrieve multple rows from my returned array from a class method. I have tried: <?php class myClass { private $connection; /* Class constructor */...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
agi2029
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,...
0
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...

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.