Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > Utility functions

runner_mail function

Scroll Prev Next More


This function helps you to send an email in PHPRunner.


To use it, you need to set up email parameters (From, SMTP server, SMTP server port, SMTP server username, SMTP server password) in the Email settings.





an array with input parameters. The following parameters are supported:

Email parameters


the sender's email address. If none is specified, an email address from the Email settings is used.


the sender's name.


the receiver's email address.


email addresses of secondary recipients.


email addresses of recipients whose addresses are not to be revealed to other recipients of the message.


the reply email address.


the message priority (use '1' for urgent, '2' - high, '3' - normal).


the plain text message body.


the html message body (do not use the 'body' parameter in this case).


the html message charset. If none is specified, the default website charset is used.


the description of the attachments. The 'path' (a path to the attachment) is required. Other parameters are optional: 'name' overrides the attachment name, 'encoding' sets the file encoding, 'type' sets the MIME type.

Attachments work only when the PHP 'mail' function is disabled.

Return value

An array with the following keys:


mailed: (true or false) indicates whether the email was sent or not.

message: an error message in case the email was not sent.


Send simple email

$message="Hello there\nBest regards";
$subject="Sample subject";
runner_mail(array('to' => $email, 'subject' => $subject,
'body' => $message));

Send HTML email

$message="Hello there\n<b>Best regards</b>";
$subject="Sample subject";
runner_mail(array('to' => $email, 'subject' => $subject,
'htmlbody' => $message, 'charset' => 'UTF-8'));

Example with error handling

$subject="Sample subject";
$arr = runner_mail(array('to' => $email, 'subject' => $subject,
'body' => $body));
// if error happened print a message on the web page
if (!$arr["mailed"])
echo "Error happened: <br>";
echo $arr["message"];

Send email with BCC and CC fields

$message="Hello there\nBest regards";
$subject="Sample subject";
runner_mail(array('to'  => $email, 'cc' => '',
'bcc' => '', 'subject' => $subject, 'body' => $message));

Send email with From and FromName fields

$message="Hello there\nBest regards";
$subject="Sample subject";
$fromName="Bill Gates";
runner_mail(array('to'  => $email, 'subject' => $subject,   'body' =>
$message, 'fromName'=> $fromName, 'from' => $from));

Send email to multiple recipients

$message="Hello there\nBest regards";
$subject="Sample subject";
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $message));

Send email with attachments

$from = "";
$to = "";
$msg = "Find some documents (Invoice.pdf, Photo.jpg, signature.jpg) attached.";
$attachments = array();
// Attachments description. The 'path'(a path to the attachment) is required. Others parameters are optional:
//'name' overrides the attachment name, 'encoding' sets a file encoding, 'type' sets a MIME type
$attachments = array(
      array('path' => getabspath('files/Invoice.pdf')),
      array('path' => getabspath('files/Photo12.jpg'),
                  'name' => 'Photo.jpg',
                  'encoding' => 'base64',
                  'type' => 'application/octet-stream'),
      array('path' => getabspath('files/signature.jpg'))
) ;
$ret = runner_mail(array('from' => $from, 'to' => $to, 'subject' => $subject, 'body' => $msg, 'attachments' => $attachments));
  echo $ret["message"];

Send email with new record data. Use this code in the After Add event.

$from = "";
$to = "";
$msg = "The new record was added: ";
$subject="New record";
$msg.= "Name: ".$values["name"]."\r\n";
$msg.= "Email: ".$values["email"]."\r\n";
$msg.= "Age: ".$values["age"]."\r\n";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
  echo $ret["message"];

See also:

Email settings

Events: AfterAdd

runner_sms function

Event editor

About predefined actions

Dialog API

A complete guide to sending emails with a web based application

MassMailer template use case


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