This topic is locked

Mail to original user

3/28/2008 4:59:40 PM
PHPRunner General questions
M
mmponline author

I use this code to send a mail to the logged in user when completing a form:

{

global $conn;

//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"];


How can I change it to send a mail to the original User when a guest (not logged in) posts info on the same form.
IOW I want the original creator to receive confirmation e-mail when anybody fills in the form on the record.
Thank you for your help!

J
Jane 3/31/2008

Stephan,
I'n not sure what does "original User" mean?

What event do you want to send email in?

M
mmponline author 3/31/2008

Jane
Certain people has the right to register and add new items. I then have a enquire form where people can enquire about the item.
When a guest enquire, they fill in a add new record form I created.

On event "after record added", I want an e-mail to go out to the person that loaded the product (LoginID)
The above event only sends it to a logged on user. In this case, it will be a guest (not logged) and the mail must be sent to the user that created the entry to confirm the enquiry. The login table has a Email field that holds the e-mail address and the main table has a LoginID connected to the LoginID in the login table.
Hope this is more clear.

J
Jane 4/1/2008

Stephan,
I'm really confused.

How to send email to the person without any data about?

M
mmponline author 4/1/2008

Let me explain from start.
An agent registers and get login info.

He then loads properties.

The item has a Request link that takes him to an add form where viewers (guest login) fill in his details and e-mail address.

This code also diplays property info on the request form

$message="<table width=60% align=center>";

$message .= "<TR><TD class=shade align=middle colSpan=2><FONT size=2><STRONG>PROPERTY ENQUIRY:</STRONG></FONT>&nbsp;</TD>";

$message .= "<TR><TD class=shade width=150>Property ID</TD><TD width=250>".$_SESSION["PropID"]."</TD>";

$message .= "<TR><TD class=shade width=150>Industry Type</TD><TD width=250>".$_SESSION["Type"]."</TD>";

$message .= "<TR><TD class=shade width=150>Property Type</TD><TD width=250>".$_SESSION["PropType"]."</TD>";

$message .= "<TR><TD class=shade width=150>Price</TD><TD width=250>".$_SESSION["Price"]."</TD>";

$message .= "<TR><TD class=shade width=150>Photo</TD><TD width=250>".$_SESSION["Photo"]."</TD>";

$message .= "<tr><td colspan=2></td></tr></table>";
echo $message;


On submission, the mail is sent to viewer:

$email=$values["Email"];



and another mail must go to the agent that originally loaded the item.

(need this code)
I have a LoginID in both the Login and Properies table as logged on agents can see others but edit their own information only on permissions.
Here is a link: http://afrdse.co.za/afdsdb/Properties_list.php - Click on enquire for form and e-mails sending.
I can upload to demo account if needed.

J
Jane 4/1/2008

Stephan,
you need to pull email from another table (Login table) using PropertyID.

Here is just a sample:

global $conn;

$str1 = "select LoginID from properties where PropID=".$_SESSION["PropID"];

$rs1 = db_query($str1,$conn);

$data1 = db_fetch_array($rs1);
$str2 = "select email from Login where LoginID=".$data1["LoginID"];

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_array($rs2);
$email2 = $data2["email"];

M
mmponline author 4/1/2008

I've changed the relevant Filed and Table names, but get a syntax error. Complete code:

{

global $conn;

$str1 = "select LogID from Properties where PropID=".$_SESSION["PropID"];

$rs1 = db_query($str1,$conn);

$data1 = db_fetch_array($rs1);
$str2 = "select Email from Login where LoginID=".$data1["LoginID"];

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_array($rs2);
$email2 = $data2["Email"];
$adminemail="mmp@mmponline.co.za";

$email=$values["Email"];

$message="Thank you for your enquiry about the following property. We will contact you soon:
Property ID: ".$_SESSION["PropID"]."

Industry Type: ".$_SESSION["Type"]."

Property Type: ".$_SESSION["PropType"]."

Price: ".$_SESSION["Price"].":\r\n\n";
$message .="";
$subject="Africa de Sud - Property Enquiry";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";



mail($email, $subject, $message, 'From: Africa de Sud <mmp@mmponline.co.za>');

mail($adminemail, $subject, $message,'From: Africa de Sud <mmp@mmponline.co.za>');

mail($mail2, $subject, $message,'From: Africa de Sud <mmp@mmponline.co.za>');

}

{

//********** Redirect to another page ************

header("Location: Properties_list.php?a=return");

exit();

}


256

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

URL afrdse.co.za/afdsdb/Enquire_add.php?

Error file /usr/www/users/afrdse/afdsdb/include/dbconnection.php

Error line 26

SQL query insert into `Enquire` (`Name`, `Surname`, `Tel`, `Fax`, `Email`) values ('vdfd', 'dgf', 'gfg', 'gf', 'test@mmponline.co.za')

Solution This is a general error. It occurs when thereis an error in event code or in SQL.

J
Jane 4/1/2008

Stephan,
this code is just a sample.

You should replace field names with yours, add single quotes if needed (around text fields in the queries).

To debug code print all queries on the page and check it manually or execute in the database directly.