Contents

 
Home
PHPRunner 6.1 manual
Prev Page Next Page
 
 

Email selected records

 

To send an email with several selected records on the List page, you need to create custom button.

yellowbulbNote: Change the values listed in red to match your specific needs.

1. Proceed to the Visual Editor page.

2. Create the custom button Update selected and add the following code

to the Server tab:

global $dal;

$dal_TableName = $dal->Table("TableName");

$body="";

foreach(@$keys as $keyblock)

{

  $arr=explode("&",refine($keyblock["FieldName"]));

  if(count($arr)<1)

    continue;

  $arr2=array();

  $arr2["FieldName"]=urldecode(@$arr[0]);

  $where = KeyWhere($arr2);

  $rstmp = $dal_TableName->Query($where,"");

  $datatmp=db_fetch_array($rstmp );

  $body .= "OrderID: " . $datatmp['OrderID'] . "\n";

  $body .= "Customer: " . $datatmp['CustomerID'] . "\n";

  $body .= "Employee: " . $datatmp['EmployeeID'] . "\n-----------\n\n";

}

 

// send the email

$email="test@test.com";

$subject="Sample subject";

$arr = runner_mail(array('to' => $email, 'subject' => $subject,

'body' => $body));

$result["txt"] = "Emails were sent.";

 

// if error happened print a message on the web page

if (!$arr["mailed"])

{

  $errmsg = "Error happened: <br>";

  $errmsg.= "File: " . $arr["errors"][0]["file"] . "<br>";

  $errmsg.= "Line: " . $arr["errors"][0]["line"] . "<br>";

  $errmsg.= "Description: " . $arr["errors"][0]["description"] . "<br>";

  $result["txt"] = $errmsg;

}

and to the Client After tab:

var message = result["txt"];

ctrl.setMessage(message);

The Client Before tab should be blank (delete sample code there if any).

Sample email message:

OrderID: 10249

Customer: TRADH

Employee: 6

-------------------

OrderID: 10251

Customer: VICTE

Employee: 3

-------------------

OrderID: 10253

Customer: HANAR

Employee: 3

-------------------

yellowbulbNote: How to send email to the current logged user

Instead of the hardcoded email address you can send it to the current logged user. If you use email address as a username use the following:

$email=$_SESSION["UserID"];

If email address is stored in another field of users table you need to save it to the session variable in AfterSuccessfulLogin event:

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

Then in BeforeProcess event code use the following:

$email=$_SESSION["email"];

Converted from CHM to HTML with chm2web Standard 2.85 (unicode)