This topic is locked

Email Attachments

4/13/2017 10:10:11 AM
PHPRunner General questions
A
Andrew S author

Hi,
I have an application I created several years ago using PHP Runner V6.2. Part of the application sends emails to customers when an update has been made to a job they have submitted. This all works fine. I have now been asked if it is possible to also send attachments.
The application uses the upload feature and stores in mysql database using medium blob. Uploads can be pdf, docx, xlsx, jpg or png.
I have attempted code I found in the forum regarding email attachments but when I receive the email, the attachment appears as text totally ineligble. I did read that I need to use custom email settings.
Can anyone please help and tell me what I am doing wrong and explain how and what I need to have custom email.
Many thanks and happy Easter.
Andrew

Admin 4/13/2017

I would suggest to check later versions of PHPRunner where runner_mail function comes with an option to attach files:

https://xlinesoft.com/phprunner/docs/runner_mail_function.htm

A
Andrew S author 4/13/2017

Thanks. I have got V7 but have not upgraded that application as I seem to recall I would have to recreate all events and there are loads. Does V7 have the functionality I am after ?
Thanks

Andrew

Admin 4/14/2017

Check the manual that comes with your version of PHPRunner. runner_mail is the function you looking for.

lefty 4/14/2017



Check the manual that comes with your version of PHPRunner. runner_mail is the function you looking for.


"Can anyone please help and tell me what I am doing wrong and explain how and what I need to have custom email"
I have same issue . Where is the custom email settings ? what changes the mail to custom. Have looked and starred at runner_mail function numerous times . It says attachments must use custom email settings. Where is the option to do this? it's not in the email settings as It states . " use PHP mail function ( not recommended ) in 9.7 . So if you use attachments where is the option to use custom mail settings? Only attachments without checking PHP mail function is to use attachments function with upload. encode/decode That works fine . What about from disk?
I cannot get this sample to work does not send email. I get the dreaded white screen after add with no errors in developer mode.
$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 = runnermail(array('from' => $from, 'to' => $to, 'subject' => $subject, 'body' => $msg, 'attachments' => $attachments));
if(!$ret["mailed"]){
echo $ret["message"];
}
[size="4"]
I have tried all types of getabspath function to no avail. But the below with upload works perfect._[/size]
$fileArray = my_json_decode($values["upload"]);
$attachments = array();
foreach($fileArray as $f)
{
$attachments[] = array("path" => $f["name"]);
}
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from, "attachments" => $attachments));

if(!$ret["mailed"])

echo $ret["message"];
} else {

}

A
Andrew S author 5/9/2017

John, not sure if this will help you but it certainly works for me. (May not be best solution but works!)
I have a table named companies and have added 2 fields - 1 is Y or N (does company require email updates) and a second field containing the email address(es) to send emails to if required.
//Check if company requires email and grab email address 28th April 2017
$_SESSION["tmpUpdate"] = DBLookup("select RequireUpdates from Companies where CompanyID=".$values['companyid']);

$_SESSION["tmpUpdateEmail"] = DBLookup("select UpdateEmail from Companies where CompanyID=".$values['companyid']);
//This checks to see if customer requires email updates and if yes, then collect the email address(s) to send to - this information held in Companies table
if ($_SESSION['tmpUpdate']=="Y") {
$email=$_SESSION["tmpUpdateEmail"];
$subject="An update has been made to job reference ".$values['jobreference'];
// System has ability to store 2 attachments into database itself (mediumblob)
//If an attachment exists, attach to email
if ($values['AttachmentTitle']==true) {
$attachments = array();
$image_1 = 'files/'.$values[AttachmentTitle];
file_put_contents($image_1, $values['Attachment']);
$attachments[] = array("path" => $image_1);
// Now check to see if there is a second attachment)
if ($values['AttachmentTitle1']==true) {

$image_2 = 'files/'.$values[AttachmentTitle1];

file_put_contents($image_2, $values['Attachment1']);
$attachments[] = array("path" => $image_2);

}
// End of check for 2nd attachment)
$msg = "";
foreach($fileArray as $f)
{
$attachments[] = array("path" => $f["name"]);
}

}
$msg.= "This is a system generated email DO-NOT-REPLY"."\n\n";
$msg.= "Work Order Details:"."\n\n";
// $msg.= "Update Required : ".$_SESSION["tmpUpdate"]."\r"; USED FOR TESTING PURPOSES ONLY

// $msg.= "Update Emails : ".$_SESSION["tmpUpdateEmail"]."\r"; USED FOR TESTING PURPOSES ONLY
$msg.= "Job Reference : ".$values["jobreference"]."\r";
$msg.= "Address : ".$values["address"]."\r";
$msg.= "Our Reference : ".$values["workorderID"]."\r";
$msg.= "Appointment Date : ".$values["AppointmentDate"]."\r";
$msg.= "Updates"."\r";
$msg.= $values["Updates"]."\r";
$msg.= "Date Completed : ".values["datecompleted"]."\n\n";
$msg.= "Regards"."\r";

$msg.= "Tracey"."\r";
$ret=runner_mail(array('to' => $email, 'bcc' => 'xxxxxx@xxxxxxx.co.uk', 'subject' => $subject, 'body' => $msg, "attachments" => $attachments));
if(!$ret["mailed"])
echo $ret["message"];
}