Good day
I'm using the PHP Attachment Mailer Class and it works perfectly. I just want to know if there is a way to add a generic name for all the attachments.
Thank you.
PHP related forum, discuss snippets, classes and tutorials
Good day
I'm using the PHP Attachment Mailer Class and it works perfectly. I just want to know if there is a way to add a generic name for all the attachments.
Thank you.
Hi,
what kind of "generic name" do you mean?
Do you attach existing files from your server or using uploaded files?
Hi
I'm attaching files from my server. All the files on the server is named clientid_clientname_clientsurname for example 1233_name_surname.pdf or 1233_name_surname.doc. So when I attach any document on the notification email I want to rename it to mycv.pdf or mycv.doc.
Hope that makes sense!
do you know how-to extend a PHP class?
you need to modify this method:
function add_attach_file($file, $encoding = "base64", $dispo = "attachment", $type = "application/octet-stream") {
$file_str = $this->get_file_data($file);
if ($file_str == "") {
return;
} else {
if ($encoding == "base64") $file_str = base64_encode($file_str);
$this->att_files[] = array(
"data"=>chunk_split($file_str),
"name"=>basename($file),
"cont_type"=>$type,
"trans_enc"=>$encoding,
"disposition"=>$dispo);
}
}
The array element "name" need to get changed.
I did change that name array element, but that didn't work. As soon as I make that change it doesn't attach the document to the email.
You need to do this dynamically, you can't just edit the function. This should work:
class my_attach_mailer extends attach_mailer {
function add_attach_file($file, $custname = '', $encoding = "base64", $dispo = "attachment", $type = "application/octet-stream") {
$file_str = $this->get_file_data($file);
if ($file_str == "") {
return;
} else {
if ($encoding == "base64") $file_str = base64_encode($file_str);
$name = ($custname != '') ? $custname : basename($file);
$this->att_files[] = array(
"data"=>chunk_split($file_str),
"name"=>$custname,
"cont_type"=>$type,
"trans_enc"=>$encoding,
"disposition"=>$dispo);
}
}
}
Using this extension, create an object like:
$myobject = new my_attach_mailer();
I didn't tried that code, but it should work this way.
Thank you - I'll give it a try.
This topic has been closed to new replies.