Email multiple people from a database
Started by kyleblackman, Oct 11 2006 03:26 PM
7 replies to this topic
#1
Posted 11 October 2006 - 03:26 PM
I have a database with emails in it. I want to be able to pull down all the emails from the database and email them all at once. There used to be a mailing list script tutorial on here but i cant find it now.
im using PHP and MySQL. thank you!
im using PHP and MySQL. thank you!
#2
Posted 11 October 2006 - 03:41 PM
i tried your code and i got an error. heres my code:
<?php
$hostname="*****";
$username="*****";
$password="*****";
$dbname="*****";
$link = mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
$db = mysql_select_db("$dbname") or die("database not selected".mysql_error()); //selects the database
$getemails = "SELECT email FROM `lag` WHERE agency='kyleblackman'";
while($user= mysql_fetch_array($getemails))
{
mail();
echo"Mail sent to" . $user['email'] . "<br/>";
}
?>
this is the error i get
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/k/y/l/kyleblackman/html/tombird/elist.php on line 9
<?php
$hostname="*****";
$username="*****";
$password="*****";
$dbname="*****";
$link = mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
$db = mysql_select_db("$dbname") or die("database not selected".mysql_error()); //selects the database
$getemails = "SELECT email FROM `lag` WHERE agency='kyleblackman'";
while($user= mysql_fetch_array($getemails))
{
mail();
echo"Mail sent to" . $user['email'] . "<br/>";
}
?>
this is the error i get
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/k/y/l/kyleblackman/html/tombird/elist.php on line 9
#3
Posted 11 October 2006 - 03:51 PM
and im pretty sure that means that your code isnt wrong, but that my query is messed up..which doesnt make sense because before i implimented your code, that query was working fine. can you see any problems here? the reason why its asking for emails where agency='kyleblackman' is because my name is attatched to 3 different emails in the database as a test so when i actually test it it should email all of my emails at the same time.. im just not having any luck.
should you need to implode the results and separate them by commas? also some agents in this database failed to include an email address, what code could i write to exclude all of the results from the query that turn up empty?
========
edited by Mr. Matt, please watch your language, this is a public forum =)
should you need to implode the results and separate them by commas? also some agents in this database failed to include an email address, what code could i write to exclude all of the results from the query that turn up empty?
========
edited by Mr. Matt, please watch your language, this is a public forum =)
Edited by Mr. Matt, 11 October 2006 - 03:58 PM.
#4
Posted 11 October 2006 - 04:13 PM
adam127, on Oct 11 2006, 04:54 PM, said:
I didnt see you had that bit of text after the code. lol
Anyway, You have edited my code
needs to be

- Adam
Anyway, You have edited my code
$getemails = "SELECT email FROM `lag` WHERE agency='kyleblackman'";
needs to be
$getemails = mysql_query("SELECT email FROM `lag` WHERE agency='kyleblackman'") or die(mysql_error());
- Adam
ooooo thats a little better its almost there! but might you be able to tell me what this error means?
Warning: mail() expects parameter 1 to be string, resource given in /home/content/k/y/l/kyleblackman/html/tombird/elist.php on line 13?
thank you so much for your help by the way
#5
Posted 11 October 2006 - 04:26 PM
$to ="$user['email']";
$subject ="subject";
$message ="message";
mail($to,$subject,$message);
thank you so much for your help so far though
$subject ="subject";
$message ="message";
mail($to,$subject,$message);
thank you so much for your help so far though
Edited by kyleblackman, 11 October 2006 - 04:29 PM.
#6
Posted 11 October 2006 - 04:33 PM
adam127, on Oct 11 2006, 05:30 PM, said:
haha yeah! thats what i figured! but its returning this error now (sorry if im makin yer head spin)
line 11 is $to ="$user['email']";
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/k/y/l/kyleblackman/html/tombird/elist.php on line 11
#7
Posted 11 October 2006 - 04:45 PM
ummm... are you sure your not a chick? cuz i fucking want to marry you right now. haha.
thanks so much .it worked wonders.
if you lived in san diego id buy you a beer right now.
thanks so much .it worked wonders.
if you lived in san diego id buy you a beer right now.
#8
Posted 11 October 2006 - 04:49 PM
hahaahah word man, well hell thank you so much. i learned a lot.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
