提问人:JKG79 提问时间:3/8/2023 最后编辑:JKG79 更新时间:3/8/2023 访问量:33
php mail_runner从文件夹而不是数据库字段发送附件
php mail_runner sending attachment from folder instead of database field
问:
我正在尝试编写一个 php 脚本,该脚本使用 php mail_runner发送附件,附件取自子目录中的文件。
这是多步骤方法的一部分,我使用 imagettftext 获取模板 jpg 培训证书,用学习者数据填充它,然后将文件保存到服务器,我已经这样做了,例如:
$filenamedate = date('Ymdhi');
$file=$filenamedate." ".$name." (".$CourseDescription .")";
$file_path="Certificates/".$file.".jpg";
成功将 .jpg 保存到 /Certificate 文件夹,下面的文件名是一个示例:
202303070135 乔纳森·格林(D1 司机政策和规则).jpg
我能够使用 mail_runner 发送一封基本的电子邮件,这对于这个项目来说是必须的,这包括普通字段,例如 to、msg、from 等。
但是,我正在努力让代码工作以附加上面保存的文件。我正在尝试大致:
$from = "[email protected]";
$to = "[email protected]";
$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));
不幸的是,这不起作用,并给了我以下错误:
致命错误:未捕获的 TypeError:无法访问字符串类型的偏移量 在字符串上
我所做的唯一其他修改导致电子邮件在附件中发送,但无法打开它。
那么,我需要做些什么才能从服务器中获取此文件并作为附件发送?
但是,我正在努力让代码工作以附加上面保存的文件。我正在尝试大致:
`$from = "[email protected]";
$to = "[email protected]";
$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));`
不幸的是,这不起作用,并给了我以下错误:
致命错误:未捕获的 TypeError:无法访问字符串类型的偏移量 在字符串上
我所做的唯一其他修改导致电子邮件在附件中发送,但无法打开它。
那么,我需要做些什么才能从服务器中获取此文件并作为附件发送?
答: 暂无答案
评论
getabspath()
$file_path
$attachments