Welcome Guest, Not a member yet? Register   Sign In
Mail attach question
#1

[eluser]Unknown[/eluser]
Hi, I have tried CI since yesterday and i make a view with a contact form (with the form helper)and it have a file input to attach a file to the mail, and it call a controller with the send mail commands. The mail is ok and come with the attach file, but when i see as attach in an email client the attach file have the temp name and not the real filename.
This is how i call the attach;

Code:
$varname = $_FILES['archivo']['name'];
$vartemp = $_FILES['archivo']['tmp_name'];
$this->email->attach($vartemp,$varname);

If i call Attach whith the $varname as firtsparameter the send mail class is unable to locate the file to attach.

Thanks in advance, sorry about the wrong english writing i am trying to learn this. Regards from Argentina.
#2

[eluser]Unknown[/eluser]
Hi, i just didnt find how to change the name displayed in attach, so i made a change in the email class adding a second parameter to the function where i pass the display name - not the filename to send - that is the name of the file when download and displayed in email client. It works great, a first parameter with the name of the file to send (ex. php987.tmp) and the second with the real name (ex. file.doc), this is useful -at least to me- when i send files from a form with an input file, that auto send the file, then i dont have to do a upload process or something like that. If this could help anyone i could attach the php class to this thread.

Regards
#3

[eluser]stepwl[/eluser]
I was having the same problem here too.

So, I have to customize 2 Email library functions in order to make it working (to support the second [$varname] param):
1. function attach()
2. function _build_message()

search for the keyword 'basename' in the _build_message() function then you will figure out how to modify it.

i hope that will help whoever is having the same problem.
#4

[eluser]Merolen[/eluser]
This worked like a charm Big Grin

Here is what I've learned from this.
First off, the MY_Email.php has to be placed in application/<and so on>/libraries.

The extension:
Guess the function could be called attach, but I don't want it to override the original function.
Code:
class MY_Email extends CI_Email {
    
    var    $_attach_new_name = array();
    
    function My_Email() {
        parent::CI_Email();
    }
    /**
     * Assign file attachments
     *
     * @access    public
     * @param    string
     * @return    string
     */        
    function new_attach($filename, $new_filename, $disposition = 'attachment')
    {            
        $this->_attach_name[] = $filename;
        $this->_attach_new_name[] = $new_filename;
        $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($new_filename))));
        $this->_attach_disp[] = $disposition; // Can also be 'inline'  Not sure if it matters
    }    
}

And then, in the lib Email.php at line 1030isj:
Inside the for loop where &filename;is set I added/edited this:
Code:
$new_filename = $this->_attach_new_name[$i]; //Added
$basename = basename($new_filename); //Edit




Theme © iAndrew 2016 - Forum software by © MyBB