Show/Hide Toolbars

Navigation: Advanced topics > Programming topics

PHPrunner32x32     PHPRunner manual


Function runner_mail

Scroll Prev Next More

 

Description

 

Function runner_mail is PHPRunner wrapper for mail() function.

 
To use it you need to setup email parameters like From, SMTP server etc in Email settings.

 

Syntax

 

runner_mail($params)

 

Arguments

 

$params - array with input parameters. The following parameters are supported:

 

from - sender email address. If none specified an email address from the wizard will be used.

 

fromName - sender name.

 

to - receiver 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 - reply email address.

 

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

 

body - plain text message body.

 

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

 

charset - html message charset. If none specified the default website charset will be used.

 

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

 

Attachments will only work when PHP mail is not in use. Email settings.

 

Return value

 

Array with the following keys:

 

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

 

message: 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"];
}