CodeCharge Studio
// Write your own code here.with the code below:
global $DBIntranetDB;
global $tasks;
$from_name = CCDLookUp("emp_name", "employees", "emp_id=".
$DBIntranetDB->ToSQL(CCGetUserID(), ccsInteger), $DBIntranetDB);
$from_email = CCDLookUp("email", "employees", "emp_id=".
$DBIntranetDB->ToSQL(CCGetUserID(), ccsInteger), $DBIntranetDB);
$to_email = CCDLookUp("email", "employees", "emp_id=".
$DBIntranetDB->ToSQL($tasks->user_id_assign_to->GetValue(), ccsInteger), $DBIntranetDB);
$headers = "From: ".$from_name."<".$from_email.">;";
$headers .= "Content-Type: text/html";
$subject = "New task for you";
$message = "The following task was submitted:<br><br>".
"Task ID: ".CCDLookUp("max(task_id)", "tasks", "user_id_assign_by=".
$DBIntranetDB->ToSQL(CCGetUserID(), ccsInteger), $DBIntranetDB)."<br><br>".
$tasks->task_desc->GetText();
mail ($to_email,$subject,$message,$headers);
$from_name = CCDLookUp("emp_name", "employees", "emp_id=".$DBIntranetDB->ToSQL (CCGetUserID(), ccsInteger),$DBIntranetDB);
Sets from_name to the value of the emp_name field for the current user.
$from_email = CCDLookUp("email", "employees", "emp_id=".$DBIntranetDB->ToSQL(CCGetUserID(), ccsInteger), $DBIntranetDB);
Sets from_email to the value of the email field in the employees table where emp_id matches the current user. The CCDLookUp function is used to retrieve a database value, while CCGetUserID retrieves the id of the currently logged in user.
$to_email = CCDLookUp("email", "employees", "emp_id=".$DBIntranetDB->ToSQL($tasks->user_id_assign_to->GetValue(), ccsInteger), $DBIntranetDB);
Sets to_email to the email of the person that is assigned to the task. The CCDLookUp function is used here to retrieve the appropriate email address.
$headers = "From: ".$from_name."<".$from_email.">;";
Add details about the sender to the email header
$headers .= "Content-Type: text/html;";
Specifies that the email will be sent in HTML format (as opposed to plain text).
$subject = "New task for you";
The subject of the email to be sent.
$message = "The following task was submitted:<br><br>"."Task ID: ". CCDLookUp("max(task_id)", "tasks", "user_id_assign_by=".$DBIntranetDB->ToSQL(CCGetUserID, ccsInteger), $DBIntranetDB)."<br><br>". $tasks->task_desc->GetText();
The variable message contains the body of the email which will be sent. The CCDLookUp function is used to retrieve the largest task id submitted by the current user (assuming that task ids are created incrementally).
mail ($to_email, $subject, $message, $headers);
Sends the email using the variables created in the above code.
Next: Use the After Update Event to Send Emails