This topic is locked
[SOLVED]

 Send email to email field of another table

11/2/2015 4:32:55 PM
PHPRunner General questions
S
stec5345 author

I need to be able to send an email to an email field from another table after record processed event. What would the correct syntax be for this in PHPrunner?
Steve

S
stec5345 author 11/4/2015

Anybody? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78210&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />



I need to be able to send an email to an email field from another table after record processed event. What would the correct syntax be for this in PHPrunner?
Steve

romaldus 11/4/2015



Anybody? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78211&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />


What do you mean with "email field from another table"? You need to explain the details of your database structure

S
stec5345 author 11/8/2015

Below is the code I am using to send an email to the session user who created the supportupdate as well as a hard coded address ($email and $email2). I need an additional email to go out to the person who created the original ticket in the support table. The support and supportupdate tables are linked on SupportID. The field that contains the email address however is in the users.UserEmail field. It is the only place the email address exists. My first question would be, do I need to link the users to the support and supportupdate table or do a query of the users table for the email address based on the user ID? At the end of the day, I want the original creator of the support ticket to get emails every time there is an update to a support ticket item.
(After Record Added to supportupdate)
$email=$_SESSION["UserEmail"];

$email2="scurrier@coastaldatadynamics.com";

$sendto=$email . "," . $email2;

$from="supportQ@statmedcaredb.com";

$msg="";

$subject="New Support Ticket Added Successfully";
$msg.= "Support ID: ".$values["SupportID"]."\r\n";

$msg.= "Support Created By: ".$values["SupportCreatedBy"]."\r\n";

$msg.= "Update Date: ".$values["SupportUpdateDate"]."\r\n";

$msg.= "Submitted By: ".$values["SupportUpdatedBy"]."\r\n";
$ret=runner_mail(array('to' => $sendto, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["Email sucessful"];
Does this help? I hope this makes sense.



What do you mean with "email field from another table"? You need to explain the details of your database structure

romaldus 11/9/2015



Below is the code I am using to send an email to the session user who created the supportupdate as well as a hard coded address ($email and $email2). I need an additional email to go out to the person who created the original ticket in the support table. The support and supportupdate tables are linked on SupportID. The field that contains the email address however is in the users.UserEmail field. It is the only place the email address exists. My first question would be, do I need to link the users to the support and supportupdate table or do a query of the users table for the email address based on the user ID? At the end of the day, I want the original creator of the support ticket to get emails every time there is an update to a support ticket item.
(After Record Added to supportupdate)
$email=$_SESSION["UserEmail"];

$email2="scurrier@coastaldatadynamics.com";

$sendto=$email . "," . $email2;

$from="supportQ@statmedcaredb.com";

$msg="";

$subject="New Support Ticket Added Successfully";
$msg.= "Support ID: ".$values["SupportID"]."\r\n";

$msg.= "Support Created By: ".$values["SupportCreatedBy"]."\r\n";

$msg.= "Update Date: ".$values["SupportUpdateDate"]."\r\n";

$msg.= "Submitted By: ".$values["SupportUpdatedBy"]."\r\n";
$ret=runner_mail(array('to' => $sendto, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["Email sucessful"];
Does this help? I hope this makes sense.


First, you must save user email in session variable.
In AfterSuccessfulLogin event:

$_SESSION["UserEmail"] = $data["UserEmail"];


and than you can use $_SESSION["UserEmail"]in After Record Added event

S
stec5345 author 11/10/2015

I have already saved my session value as I am already sending an email to the SESSION user successfully. This is not what I am trying to accomplish. I want to send an email to the person who created the support ticket when a support ticket is updated. So, I need to cross reference this user, who is not necessarily the SESSION user. The value for this user is in the supportupdate.SupportUpdatedBy field. There are three tables at play here.... 1- users, 2- support, and 3- supportupdate. (relations- 1 support ticket to many updates and one User to many tickets). Support items are created in the support table, updates to support ticket items are created in the supportupdate table and user table is reference only for SESSION variable or Username and UserEmail. These SESSION variables have already been set like you suggested.
Lets see if I can explain it better:
I already send an email to the SESSION user successfully and an additional email to a hardcoded address.

I want to send an additional (3rd) email to the person who created the original support ticket (field found in the support table SupportCreatedBy field). However, in order to obtain the email address of the original support ticket creator, it has to be cross referenced in the user table. So, "after Record Added" of the supportupdate table, an additional email to the original creator needs to go out with the updated record.
I realize that I might need to restructure my data but just need to have a little guidance. Would it be easier and more feasible to some how auto populate the email addresses of the creator of the support ticket into a field of the supportupdate table? If so, how can I auto populate this?
Steve



First, you must save user email in session variable.
In AfterSuccessfulLogin event:

$_SESSION["UserEmail"] = $data["UserEmail"];


and than you can use $_SESSION["UserEmail"]in After Record Added event

Sergey Kornilov admin 11/10/2015

If session variable $_SESSION["UserEmail"] stores email address of the current logged user then you can simply use $_SESSION["UserEmail"] as a default value of SupportCreatedBy field.
Another option is to use BeforeAdd event and the following code:

$values["SupportCreatedBy"]=$_SESSION["UserEmail"];
romaldus 11/11/2015

Yes, as admin said use

$values["SupportCreatedBy"]=$_SESSION["UserEmail"];

in before record addedevent. Every time a user fills the data then SupportCreatedBy field will be filled automatically with the value of $_SESSION["UserEmail"]
In After Record added use:

$email=$values["SupportCreatedBy"];


to send email

S
stec5345 author 11/11/2015

The $_SESSION email keeps coming up. I am already sending an email to the SESSION user successfully. I don't know how else to explain my need. Is there not a way to have a phone call with you Sergey?

The SupportCreatedBy has only a first initial and last name such like "scurrier". It does not contain an email address. I need to cross reference that user name with the User table to get the email address of the user to send an email to. It is not the SESSION USER. Here is my Flow:
Open support from Support Tab

Open supportupdate (link next to line item support ticket)

Add new supportupdate

on Save, send email to-

-$_SESSION[UserEmail]

-Hard coded email (scurrier@coastaldatadynamics.com)

-SupportCreatedBy from related support table (select "UserEmail" from "users" where "support.SupportCreatedBy" = "users.UserName")


As you can see above, there are three emails that need to go out when SupportUpdate is saved. The one in Bold is the one I am trying to figure out the correct syntax for.
Steve



Yes, as admin said use

$values["SupportCreatedBy"]=$_SESSION["UserEmail"];

in before record addedevent. Every time a user fills the data then SupportCreatedBy field will be filled automatically with the value of $_SESSION["UserEmail"]
In After Record added use:

$email=$values["SupportCreatedBy"];


to send email

Sergey Kornilov admin 11/11/2015

Steve,
if you need help from support contact our support team directly. This is not even a support forum.
The problem is that you only providing us bits of info that is not enough to answer your question. We need to see the whole picture.

romaldus 11/11/2015

Try this :



$sql="SELECT UserEmail as mx from users WHERE UserName = $values["SupportCreatedBy"];

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

$email=$data["mx"];
S
stec5345 author 11/12/2015

Sending reply to this to support as I do not want to put this on the forum.

Sergey Kornilov admin 11/14/2015

This is what worked at the end.
In each event of SupportUpdate table where you send that email add the following in the beginning.

$sql = "select SupportCreatedBy from support where SupportID=".$values["SupportID"];

$email3=DBLookup($sql);



Now instead of

$sendto=$email . "," . $email2;



you can use

$sendto=$email . "," . $email2.",".$email3;