Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics

PHPrunner32x32     PHPRunner manual


Function runner_mail

Scroll Prev Next More

Description

The runner_mail function is a wrapper for the mail() function 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="test@test.com";
$message="Hello there\nBest regards";
$subject="Sample subject";
runner_mail(array('to' => $email, 'subject' => $subject,
'body' => $message));

Send HTML email

$email="test@test.com";
$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="test@test.com";
$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="test@test.com";
$message="Hello there\nBest regards";
$subject="Sample subject";
runner_mail(array('to'  => $email, 'cc' => 'test2@test.com',
'bcc' => 'test3@test.com', 'subject' => $subject, 'body' => $message));

Send email with From and FromName fields

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

Send email to multiple recipients

$email="test@test.com,test2@test.com,test3@test.com";
$message="Hello there\nBest regards";
$subject="Sample subject";
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $message));

Send email with attachments

$from = "myemail@test.com";
$to = "myclient@test.com";
$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 = "myemail@test.com";
$to = "myclient@test.com";
$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