Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > Utility functions

runner_mail function

Scroll Prev Next More

Description

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.

Syntax

runner_mail($params)

Arguments

$params

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

Email parameters

from

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

fromName

the sender's name.

to

the receiver's email address.

cc

email addresses of secondary recipients.

bcc

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

replyTo

the reply email address.

priority

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

body

the plain text message body.

htmlbody

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

charset

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

attachments

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.

Examples

Send simple email

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

Send HTML email

$email="[email protected]";
$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

$email="[email protected]";
$subject="Sample subject";
$body="test";
$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

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

Send email with From and FromName fields

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

Send email to multiple recipients

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

Send email with attachments

$from = "[email protected]";
$to = "[email protected]";
$msg = "Find some documents (Invoice.pdf, Photo.jpg, signature.jpg) attached.";
$subject="Documents";
 
$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));
 
if(!$ret["mailed"]){
  echo $ret["message"];
}

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

$from = "[email protected]";
$to = "[email protected]";
$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));
if(!$ret["mailed"]){
  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