Please enable JavaScript to view this site.

Navigation: Advanced topics > Events > Sample events > Email

Send an email with an attachment from the database

Scroll Prev Next More

 

To send an email with attachments stored in a database field, use the following code in events like BeforeAdd/AfterAdd/BeforeEdit/AfterEdit.

 

Make sure to replace "Field that stores attachments" with the actual field name. This must be a TEXT or VARCHAR(max) field that is set up as File/Image in PHPRunner.

 

Note: Attachments will only work when you selected "Use custom mailer server settings" under "Email settings".

 

 

$email= "[email protected]" ;
$msg="File Attached";
$subject="Attached some files";
 
$fileArray = my_json_decode($values["Field that stores attachments"]);
$attachments = array();
$msg = "";
foreach($fileArray as $f)
{
  $attachments[] = array("path" => $f["name"]);
}
 
$msg.= "Some field: ".$values["Some field"]."\r";
$msg.= "Some other field: ".$values["Some other field"]."\r";
 
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, "attachments" => $attachments));
if(!$ret["mailed"])
  echo $ret["message"];

 

See also:

Send simple email

runner_mail function

How to email selected records as separate PDF files

Email selected records

Send an email to all users

Send an email to selected users

Send an email with updated fields only

 

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