This topic is locked

Sending an e-mail

1/24/2007 3:30:31 PM
PHPRunner General questions
M
mmponline author

I need a event to send a e-mail to a user to eg. say:

"Thank you for your registration, etc" and also include the fields filled in or
"Thank you for your order" and then the details.
The event must:

  1. send a mail to the administrator (This would probably be the event code snippet for send e-mail after save - that I can do)
  2. and then also to the user's email address (email field)
  3. The user's e-mail address might have to be drawn from another table (say the registration / login table)
  4. Lastly selected fields must be included in the e-mail as well.
    Will appreciate any help...
    Stephan

J
Jane 1/25/2007

Stephan,
use Before record updated event for your purpose.

Here is a sample. No guarantee it works.

function BeforeAdd(&$values)

{

global $conn;
//admin email

$adminemail="test@test.com";
//select user email from LoginTable

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

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

$data = db_fetch_array($rs);

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

$message="";

$subject="New data record";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($adminemail, $subject, $message);

mail($useremail, $subject, $message);
return true;

}

M
mmponline author 1/25/2007

Jane
I've tried this with the following code. My changes marked in . No e-mails came through but also no error messages. Did I make the right replacements? i tried some other options, but had no luck...
function BeforeAdd(&$values)

{

global $conn;
//admin email

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

$str = "select * from [color="#FF0000"]EmplLogin where UserName = '".$_SESSION["."'";

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

$data = db_fetch_array($rs);

$useremail = $data["[b][color=#FF0000]E-mail
"];
//message

$message="Your info was updated";

$subject="Data record updated";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
mail($adminemail, $subject, $message);

mail($useremail, $subject, $message);
return true;

}

Alexey admin 1/26/2007

Stephan,
$_SESSION["UserID"] contains name of the user currently logged in.

$_SESSION["EmplID"] doesn't mean anything.
Use either $_SESSION["UserID"] or $values["EmplID"] in your code.