This topic is locked

Sending email with attachment from the database

7/19/2013 7:03:28 AM
PHPRunner Tips and Tricks
Sergey Kornilov admin

Here is the sample code to send an email with attachments stored in database field. Use in events like BeforeAdd/AfterAdd/BeforeEdit/AfterEdit. Make sure to replace "Field that stores attachments" with the actual field name.

$email= "test@gmail.com" ;

$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"];