CodeIgniter Forums
Attaching a file, sending with Email class - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Attaching a file, sending with Email class (/showthread.php?tid=12377)

Attaching a file, sending with Email class - El Forum - 10-16-2008

Hey all. I'm pretty frustrated at this point. I have spent way too long trying to figure something out, that I know must be simple!

I simply want to attach and send a file in an email, through a form. I am sure my code isn't the best, but here is the controller.


class Form extends Controller {
    function index()
        $this->load->helper(array('form', 'url'));
        $rules['name']    = "required";
        $rules['phone']    = "required|alpha_dash";
        $rules['email']    = "required|valid_email";        
        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        $fields['name'] = 'Name';
        $fields['organization'] = 'Organization';
        $fields['phone'] = 'Phone';
        $fields['email'] = 'Email';
        $fields['quantity'] = 'Quantity';
        $fields['message'] = 'Message';

        $service = "";
            $services = $this->input->post('services');
            for($i=0;$i<(count($services));$i++) {
                $service .= ($services[$i].", ");
                //echo $services[$i].", ";
        $name = $this->input->post('name');
        $email = $this->input->post('email');
        $organization = $this->input->post('organization');
        $phone = $this->input->post('phone');
        $quantity = $this->input->post('quantity');
        $artwork = $this->input->post('artwork');
        $message = $this->input->post('message');
        if ($this->validation->run() == FALSE)
            $this->email->from($email, '');
            $this->email->to('[email protected], [email protected]');
            $this->email->subject('Quote Request');
            $this->email->message("Name: ".$name."\r\nOrganization: ".$organization."\r\nPhone #: ".$phone."\r\nEmail Address: ".$email."\r\nQuantity Nedded: ".$quantity."\r\nServices Needed: ".$service."\r\nMessage: ".$message);
            if($artwork) {
                           echo $artwork;


Before I added the attachment code, the form properly displayed validation error, and sent correctly.

Now, it will take a second, like it's loading the attachment, and most of the time displays a success message. If I don't attach a file, it actually shoots the email. If I attach a file it does not send. AND, I only got an error message once. It said I had improper parameters.

Any help? I would be most grateful.

Attaching a file, sending with Email class - El Forum - 10-21-2008

[eluser]Christopher Blankenship[/eluser]
Here goes: first is the form a multitype set and is the artwork field a type of file if you are attempting to have people upload the image to the server.

If yes then here is why you are having a problem. First you have to upload the file to the server, currently in your code you are treating it as a text field. Use the upload class to help with that then artwork would need to be the full path to the file on the server to attach it.

Hope this helps you plan your course of action.