I am trying to write a php script that sends an attachment using php mail_runner with an attachment taken from a file within a subdirectory.
This is part of a multi step approach, where I have used imagettftext to take a template jpg training certificate, fill it in with the learners data and then save the file to the server, which I have done, for example:
$filenamedate = date('Ymdhi');
$file=$filenamedate." ".$name." (".$CourseDescription .")";
$file_path="Certificates/".$file.".jpg";
Does successfully save the .jpg to the /Certificate folder, the filename below is an example:
202303070135 Jonathan Green (D1 Policy and Rules for Drivers).jpg
I am able to send a basic email using mail_runner, which is a must for this project, this includes the normal fields such as to, msg, from, etc.
However, I am struggling to get the code working to attach the file that has been saved above. What I am trying is roughly:
$from = "myemail@test.com";
$to = "myclient@test.com";
$msg = "Test Documents 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('path' => getabspath('$file_path'),
'name' => 'testcertificate.jpg',
'encoding' => 'base64',
'type' => 'application/octet-stream');
$ret = runner_mail(array('from' => $from, 'to' => $to, 'subject' => $subject, 'body' => $msg, 'attachments' => $attachments));
Unfortunaley this does not work and gives me the following error:
Fatal error : Uncaught TypeError: Cannot access offset of type string on string
The only other modification ive made results in the email being sent with at attachment, but not been able to open it.
So, what do I need to do to grab this file from the server and send as an attachment?
However, I am struggling to get the code working to attach the file that has been saved above. What I am trying is roughly:
`$from = "myemail@test.com";
$to = "myclient@test.com";
$msg = "Test Documents 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('path' => getabspath('$file_path'),
'name' => 'testcertificate.jpg',
'encoding' => 'base64',
'type' => 'application/octet-stream');
$ret = runner_mail(array('from' => $from, 'to' => $to, 'subject' => $subject, 'body' => $msg, 'attachments' => $attachments));`
Unfortunaley this does not work and gives me the following error:
Fatal error : Uncaught TypeError: Cannot access offset of type string on string
The only other modification ive made results in the email being sent with at attachment, but not been able to open it.
So, what do I need to do to grab this file from the server and send as an attachment?