Email To Multiple Recipients On Detail Table Insert

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Niijimasama
User
Posts: 85

Email To Multiple Recipients On Detail Table Insert

Post by Niijimasama »

Hi,
I have 2 tables: Flights(Master) and Flight Rows(Details).
On insert, I have some code sending email on the master table Email_Sending event as below:

                     //Get Job ID
		$SoNo = ew_ExecuteScalar("select Code from [dbo].[@FLIGHTROWS] where U_DocEntry =
		".$Args["rsnew"]["DocEntry"]."");
		//Get Customer
		$Cust = ew_ExecuteScalar("select U_CustomerName from [dbo].[@FLIGHTROWS] where U_DocEntry =
		".$Args["rsnew"]["DocEntry"]."");
		//Get Cargo Type
		$Ctype = ew_ExecuteScalar("select U_CargoType from [dbo].[@FLIGHTROWS] where U_DocEntry =
		".$Args["rsnew"]["DocEntry"]."");
		//Get Weight
		$Weight = ew_ExecuteScalar("select U_Weight from [dbo].[@FLIGHTROWS] where U_DocEntry =
		".$Args["rsnew"]["DocEntry"]."");
		
		//$Email -> ReplaceRecipient("onyangomeister@gmail.com");//ReplaceRecipient (GetRecommendmail($Args["rsnew"]["country"]));
		$Email -> Cc = CurrentUserInfo("email_addr");
		//$Email->AddCc()
		$Email -> Subject = "JOB ORDER COMPLETED" ; // Change the subject Email
		$Email -> Content = "Flight Number: ".$Args["rsnew"]["DocEntry"]."<br/>";
		$Email -> Content .="Sales/Job Order Number: ".$SoNo."<br/>";
		$Email -> Content .="Customer: ".$Cust."<br/>";
		$Email -> Content .="Cargo Type: ".$Ctype."<br/>";
		$Email -> Content .="Plane Registration: ".$Args["rsnew"]["U_FlightNumber"]."<br/>";
		$Email -> Content .="Rotation: ".$Args["rsnew"]["U_Source"].",".$Args["rsnew"]["U_Destination"]."<br/>";
		$Email -> Content .="Weight(KG): ".$Weight."<br/>";
		$Email -> Content .="Status: Ready for Invoicing";

This code works successfully when inserting only one record to the detail table, but when there are multiple detail items inserted, an email is only sent for the first item inserted.
I understand that part of the problem is that ew_ExecuteScalar() only fetches the 1st result, and I should probably change it.
My problem is how to modify this code to send emails when the items inserted in the details table are more than one.
Any assistance would be appreciated.


digitalphotoworld
User
Posts: 416
Location: Nürnberg/Germany

Post by digitalphotoworld »

If you need more than one email, I wouldn't use Email_Sending event. You should better use Row_Inserted event (from the detail-table!) and create your own cEmail-Object.

The Row_Inserted event is fired for each record and your email is sent as often as you add records.

Start with something like this:

$newmail = new cEmail;
$newmail->Recipient = "info@example.com";
$newmail->Subject = "The Subject of the Email";
$newmail->Content = "The Content of the Email";

...
$newmail->Send()


mobhar
User
Posts: 11700

Post by mobhar »

  1. You may simply use ew_Execute() global function to get the email list, and then transform the recordset result into a comma separated value, just like shown in example below.

  2. You may include more than one email into Recipient property, by separating them with choma character, for example:

...
$newmail->Recipient = "info@example.com, another@example.com, john@example.com";
...


Niijimasama
User
Posts: 85

Post by Niijimasama »

@Mohbar, @digitalphotoworld. Thank you for your guidance. I ended up combining both your suggestions and came up with the following code and placed it in the:

////*************EMAIL ALERTS***************************************
$newmail = new cEmail;
//Get Flight Number
$FlNo = ew_ExecuteScalar("select DocEntry from [dbo].[@FLIGHTS] where DocEntry =
".$rsnew["U_DocEntry"]."");
//Get Source
$Src = ew_ExecuteScalar("select U_Source from [dbo].[@FLIGHTS] where DocEntry =
".$rsnew["U_DocEntry"]."");
//Get Destination
$Dest = ew_ExecuteScalar("select U_Destination from [dbo].[@FLIGHTS] where DocEntry =
".$rsnew["U_DocEntry"]."");
//Get Plane registration
$FlReg = ew_ExecuteScalar("select U_FlightNumber from [dbo].[@FLIGHTS] where DocEntry =
".$rsnew["U_DocEntry"]."");

//	$newmail = new cEmail;
//$Email -> ReplaceRecipient("onyangomeister@gmail.com");//ReplaceRecipient (GetRecommendmail($Args["rsnew"]["country"]));
$newmail -> AddCc(CurrentUserInfo("email_addr"));
//$Email->AddCc()
$newmail -> Subject = "SALES/JOB ORDER COMPLETED" ; // Change the subject Email
$newmail -> Content = "Flight Number: ".$FlNo."<br/>";
$newmail -> Content .="Sales/Job Order Number: ".$rsnew["Code"]."<br/>";
$newmail -> Content .="Customer: ".$rsnew["U_CustomerName"]."<br/>";
$newmail -> Content .="Cargo Type: ".$rsnew["U_CargoType"]."<br/>";
$newmail -> Content .="Plane Registration: ".$FlReg."<br/>";
$newmail -> Content .="Rotation: ".$Src.",".$Dest."<br/>";
$newmail -> Content .="Weight(KG): ".$rsnew["U_Weight"]."<br/>";
$newmail -> Content .="Status: Ready for Invoicing";
$newmail->Send();
}

Now to modify it for the row updated event.
Again Thank you very much.


Post Reply