This topic is locked

Sending mail to owner

9/14/2007 5:01:56 AM
PHPRunner General questions
M
mmponline author

I use this code to send confirmation e-mails to admin and the Logged in user, and it works fine.

{

global $conn;
//admin email

$adminemail="mmp@mmponline.co.za";
//select user email from LoginTable

$str = "select * from login where UserName = '".$_SESSION["UserID"]."'";

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

$data = db_fetch_array($rs);

$useremail = $data["email"];
//message

$subject="New listing on holidayswanted.co.za";
$message="Thank you for listing with holidayswanted.co.za.

:\r\n";
$message.="ID: ".$values["LogID"]."";

$message.=" - ".$values["Name"]."\r\n\n";

$message.="Listing Period and Amount Due : ".$values["ListingPeriod"]."\r\n\n";
$message.="Your listing details are as follows. Feel free to logon and change your info at any time.\r\n\n";

foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($adminemail, $subject, $message,"From: mmp@mmponline.co.za");

mail($useremail, $subject, $message, "From: mmp@mmponline.co.za");
return true;

}


My need is now to use a similar code to send a confrmation e-mails to the user and admin when I activate this entry. (Have a query that shows only active members). My problem with this code however is that when I log in as Admin, I get both the messages, as the one is send to the hardcodes adminemail, while the other is sent to the logged in user (in this case also admin). The need is to have the second e-mails sent to the owner (LoginID is saved in this table) So, second e-maill not to the logged in user, but to the owner of the entry.
Please help!

Alexey admin 9/14/2007

Stephan,
looks like you need to use $values["LoginID"] instead of $_SESSION["UserID"] in your code.

Also to avoid sending two email to admin modify the last lines of code this way:

mail($adminemail, $subject, $message,"From: mmp@mmponline.co.za");

if($adminemail!=$useremail)

mail($useremail, $subject, $message, "From: mmp@mmponline.co.za");

M
mmponline author 9/14/2007

I've done as said but then only receives the admin e-mail. The usermail is not sent. What did I do wrong.?
If of importance: My table is login, my Login field is ID and my UserName field is username. The email is as in the code.

//select user email from LoginTable

$str = "select * from login where UserName = '".$values["LoginID"]."'";

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

$data = db_fetch_array($rs);

$useremail = $data["email"];
Alexey admin 9/14/2007

Stephan,
I recommend you to print SQL string on the page using

echo $str;

command.

Then exec it directly at your MySQL server to find what's wrong there.

M
mmponline author 9/14/2007

I'm not sure how to do this. Tried to add it at the end of the code, but nothing happens. Still only sends the admin mail.

Sergey Kornilov admin 9/15/2007

//select user email from LoginTable

$str = "select * from login where UserName = '".$values["LoginID"]."'";

echo $str;

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

$data = db_fetch_array($rs);

$useremail = $data["email"];

M
mmponline author 2/7/2008

Dropped this for some time, but it is not resolved yet. I get the following error message:
select * from login where UserName = ''
And Error happened: Undefined variable: conn

J
Jane 2/8/2008

Stephan,
you need to declare $conn variable at the beginning of your code:

//select user email from LoginTable

global $conn;

$str = "select * from login where UserName = '".$values["LoginID"]."'";

echo $str;

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

$data = db_fetch_array($rs);

$useremail = $data["email"];



Also make sure that LoginID is your actual field names where Username is stored.