Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: Send an email to users when a status field is changed. [Solved] (Read 2716 times) previous topic - next topic

Send an email to users when a status field is changed. [Solved]

How can I add some code so an email is sent to a specific user (there is a candidate's table) when the status is changed in a table.
There is also a status table where I will enter the HTML code of the email that has to be sent.

I already read in other post how to send the email but I need to know how to extract the HTML code I mentioned earlier and send the email. Is there a way to do a lookup of database tables with shortcodes or something?

Thank you,

Carlos

 

Re: Send an email to users when a status field is changed.

Reply #2
@zolwito‍ this question has already been asked and answered here. Please go through it, thanks.

Willvin, the email sending is not the problem I am already sending emails.
What I need is to get a value from a record in a different table than the one I'm inserting in.

For example, I am changing the status of the user and after inserting the change in the "users" table, I need to get the text for the body of the email from the status table. The user goes from "contacted" to "meeting". The text for the "meeting" status is in the "status" table and I need that text so I can send the email with the correct information.

How do I get that field from another table? (I know that I can get values from the same table with $modeldata['fieldname'])

Thank you,

Carlos

Re: Send an email to users when a status field is changed.

Reply #3
@zolwito‍ you can use the rawQuery function
Code: [Select]
$newData = $db->rawQuery("put your sql query here");

to get more than one record
OR the function rawQueryOne
Code: [Select]
$newData = $db->rawQueryOne("put your sql query here");

to get a single record from the table you want.

Re: Send an email to users when a status field is changed.

Reply #4
Thank you for the reply.

I get a message saying ARRAY and I tried getting the elements from the array but I don't get anything.

Code: [Select]
$status_text = $db->rawQueryOne("SELECT texto_email FROM status WHERE id_status ='" . $modeldata['status_id'] . "'");
$mailer    = new Mailer;
$mailer->send_mail("myemail@gmail.com", "An Example Subject", "The message to be sent.<br><br>-->$status_text<--<br><br><br><br>IT Team");

And in the email I get: -->Array<-- where the $status_text is inserted.

I have tried with all this options:
Code: [Select]
$status_text[0];
$status_text[1];
print_r($status_text);
And all the same result.

Any hint?

Regards,

Carlos

Re: Send an email to users when a status field is changed.

Reply #5
Already solved it.

Code: [Select]
$status_text = $db->rawQueryOne("SELECT text_email FROM status WHERE id_status ='" . $modeldata['status_id'] . "'");
$mailer    = new Mailer;
$texthtml = $status_text['text_email'];

$mailer->send_mail("myemail@gmail.com", "An Example Subject", "The message to be sent.<br><br>texthtml-->$texthtml<--<br><br><br>IT Team");

The trick was no to call the Array with index but with the name of the field.

Thank you.