This topic is locked

Mail table addresses

2/1/2008 3:32:29 PM
PHPRunner General questions
F
funkfish author

Hello,
How can I send an email to names from another table?
Example....
Table A

a@aol.com

b@aol.com

c@aol.com
mail(TableA,subject,message,headers)
Thanks in advance!

J
Jane 2/4/2008

Hi,
use following code to select all email addresses from TableA:

global $conn;

$email = "";

$str = "select EmailAddress from TableA";

$rs = db_query($str,$conn);

while ($data = db_fetch_array($rs))

$email.= $data["EmailAddress"].",";
$email = substr($email,0,-1);



where EmailAddress is your actual field name, TableA is your actual table name.

F
funkfish author 2/4/2008

AWESOME!!!! THANK YOU

Hi,

use following code to select all email addresses from TableA:
where EmailAddress is your actual field name, TableA is your actual table name.

M
mmponline 2/10/2008

...and how do I change this code to send the e-mail to a specific user in the foreign table. The two tables are related with a master detail relationship.

J
Jane 2/11/2008

Stephan,
just add where clause to your SQL query:

global $conn,$strTableName;

$email = "";

$str = "select EmailAddress from ForeignTable where ForeignKey=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["EmailAddress"];

M
mmponline 2/12/2008

I'm struggling:
I get the folowing error:

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
My code:

global $conn,$strMMPProjectProgress;

$email = "";

$str = "select ProjEmail from MMPProjects where ProjectID=".$_SESSION[$strMMPProjectProgress."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["ProjEmail"];


Table where event is in: MMPProjectProgress
Foreign table: MMPProjects

ForeignID: ProjectID

RelatedKey: ProgressID

Email to be sent to: ProjEmail
Please help!!!

J
Jane 2/12/2008

Stephan,
don't replace $strTableName with another variable:

global $conn,$strTableName;

$email = "";

$str = "select ProjEmail from MMPProjects where ProjectID=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["ProjEmail"];

M
mmponline 2/12/2008

Thanks Jane
100%

M
mmponline 2/12/2008

Jane
How do I repeat this event to also send a mail to a different field (with e-mail address) in the same foreign table. In fact, the mail must go to 3 fields
Something like this:

...
global $conn,$strTableName;

$email = "";

$str = "select ProjEmail from MMPProjects where ProjID=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["ProjEmail"];
global $conn,$strTableName;

$email = "";

$str = "select RPmail from MMPProjects where ProjID=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["RPmail"];
...



This one gives a syntax error...

J
Jane 2/13/2008

Stephan,
try to use this code:

global $conn,$strTableName;

$email = "";

$str = "select ProjEmail,RPmail from MMPProjects where ProjID=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["ProjEmail"].",".$data["RPmail"];

J
Jane 2/13/2008

Stephan,
try to use this code:

global $conn,$strTableName;

$email = "";

$str = "select ProjEmail,RPmail from MMPProjects where ProjID=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

$email = $data["ProjEmail"].",".$data["RPmail"];

M
mmponline 2/13/2008

Thanks Jane
It's perfect for my needs.
My own tips and tricks DB is getting bigger everyday, thanks to your excellent support. I wlll psot some of it in the forum.