This topic is locked

Attaching document stored in database to email

9/25/2013 6:16:19 AM
PHPRunner General questions
J
jasonfrew author

Hi All
I would like to attach a document

stored on my network to an email.
I have a Custom button that picks up selected records and emails to an email address thats been entered by the user.
At the moment when i tell the email to pick up the field that has the file uploaded to it it only takes the file location information stored in the database..
It looks like this Document: [{"name":"\\\\192.168.44.2\\Docstore\/P0400-151-F100-009-01-A01-001-01 REV 01_uda3n5c6.pdf","usrName":"P0400-151-F100-009-01-A01-001-01 REV 01.pdf","size":150003,"type":"application\/pdf","searchStr":"P0400-151-F100-009-01-A01-001-01 REV 01.pdf,!:sStrEnd"}]
I would like it to attach the file to the email.
I have found this code snippet in the tips and tricks section of the forum


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


This would work is i had the file stored in the database in a binary field. However unfortunatly i dont. the file is uploaded to a network drive
Can anyone offer any advice.

Sergey Kornilov admin 9/25/2013

Your assumption is incorrect. This code works with files stored on server hard drive. Only file info is stored in the database.

J
jasonfrew author 9/26/2013

So ive now enabled custom SMTP through gmail
the code in my aplications looks like the following based on advice from admin

$email = $params['email'];

$msg="File Attached";

$subject="Attached some files";
$fileArray = my_json_decode($values["Doc_file"]);

$attachments = array();

$msg = "";

for($i = 0; $i < count($fileArray); $i++)

{

$fileName = $fileArray[$i]["name"];

$name = $fileArray[$i]["usrName"];

$attachments[] = array("path" => $fileName, 'name' => $name);

}
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, "attachments" => $attachments));

if(!$ret["mailed"])

echo $ret["message"];


My Assumption is that im not changing the following fields.

$fileName = $fileArray[$i]["name"];

$name = $fileArray[$i]["usrName"];


Can some describe to me what these two lines are doing. This will give me a bit of help in deciding what to do with them