Please enable JavaScript to view this site.

Navigation: Advanced topics > Events > Sample events > Email

PHPrunner32x32     PHPRunner manual


Email selected records

Scroll Prev Next More

How to send an email to a predefined address

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

 

1. Proceed to the Page Designer screen.

 

2. Create an Update selected custom button and add the following code snippets into it:

Server tab:

Note: Change red values to match your project.

 

$body = "";
while( $data = $button->getNextSelectedRecord() )
{
  $body .= "OrderID: " . $data['OrderID'] . "\n";
  $body .= "Customer: " . $data['CustomerID'] . "\n";
  $body .= "Employee: " . $data['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;
}

Client After tab:

var message = result["txt"];
ctrl.setMessage(message);

 

Note: 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

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

How to send an email to the currently authorized user

Instead of a hardcoded email address, you can send email to the current user.

1. The email address is used as the username

$email=$_SESSION["UserID"];

2. The email address is stored in an individual field

In this case, you need to save the email address to the session variable in the AfterSuccessfulLogin event:

 

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

 

BeforeProcess event code:

 

$email=$_SESSION["email"];

See also:

Inserting custom button

Update selected

Tri-part events

Send an email to all users

Send an email to selected users

Send simple email

How to email selected records as separate PDF files

Grid Row Javascript API: row.getKeys()

JavaScript API:getSelectedRecordKeys()

Button object: getNextSelectedRecord()

runner_mail function

AJAX helper object: setMessage()

 

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software