Welcome Guest, Not a member yet? Register   Sign In
file upload not working
#1

[eluser]cucaw[/eluser]
So I am stumped. The email is sent but there is not file uploaded to the uploads file i have in my html file. But in the email, and empty attachment is sent along with the form input. ANYTHING would help right now. It's probably something silly.

Thanks!


Code:
function contact2() {
  $this->load->library('form_validation');
  //validate form input crap  
  $this->form_validation->set_rules('name', 'Name', 'trim|required');
  $this->form_validation->set_rules('company', 'Company', 'trim');
  $this->form_validation->set_rules('street_address', 'Street Address', 'trim|required');
  $this->form_validation->set_rules('city', 'City', 'trim|required');
  $this->form_validation->set_rules('state', 'State', 'trim|required');
  $this->form_validation->set_rules('zip', 'Zip', 'trim|required');
  $this->form_validation->set_rules('phone', 'Phone', 'trim|required');
  $this->form_validation->set_rules('country', 'Country', 'trim|required');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  $this->form_validation->set_rules('manufacturer', 'Manufacturer', 'trim|required');
  $this->form_validation->set_rules('part', 'Part Number', 'trim|required');
  $this->form_validation->set_rules('quantity', 'Quantity', 'trim|required');
  $this->form_validation->set_rules('datepicker', 'Wanted By', 'trim|required');
  $this->form_validation->set_rules('reference', 'How did you hear of us?', 'trim|required');
  $this->form_validation->set_rules('comments', 'Comments', 'trim');
  
  if($this->form_validation->run() == FALSE) {
   //exit('Must Fill in All Required Input Fields');
   $this->index();
  } else {
   $name = $this->input->post('name');
   $company = $this->input->post('company');
   $street_address = $this->input->post('street_address');
   $city = $this->input->post('city');
   $state = $this->input->post('state');
   $zip = $this->input->post('zip');
   $country = $this->input->post('country');
   $phone = $this->input->post('phone');
   $email = $this->input->post('email');
   $manufacturer = $this->input->post('manufacturer');
   $part = $this->input->post('part');
   $quantity = $this->input->post('quantity');
   $wantedby = $this->input->post('datepicker');
   $reference = $this->input->post('reference');
   $comments = $this->input->post('comments');
//upload crap  
   $config['upload_path'] = './uploads/';
   $config['allowed_types'] = 'png|jpg|jpeg|pdf|doc|docx';
   $config['max_size'] = '3000';
   $this->load->library('upload', $config);
   $datas = array('upload_data' => $this->upload->data());
  
   // Prepare the email message
   $message = "";  
   $message .= "A quote has been requested for the following item by:\n\n";
   $message .= "Name: $name\n";
   $message .= "Company: $company\n";
   $message .= "Address: $street_address\n";
   $message .= "City: $city\n";
   $message .= "State: $state\n";
   $message .= "Zip: $zip\n";
   $message .= "Country: $country\n";
   $message .= "Contact Phone #: $phone\n";
   $message .= "Email Address: $email\n";
   $message .= "Name: $name\n\n";
   $message .= "Manufacturer: $manufacturer\n";
   $message .= "Part #: $part\n";
   $message .= "Quantity: $quantity\n";
   $message .= "Wanted By: $wantedby\n";
  
   $message .= "Found us how: $reference\n\n";
   $message .= "Comments:\n$comments\n\n";
$this->load->library('email');

   $this->email->from($email, $name);
   $this->email->to('[email protected]');
   //$this->email->cc('[email protected]');
   //$this->email->bcc('[email protected]');
   $this->email->attach($datas['upload_data']['file_path'].$datas['upload_data']['file_name']);//attach the file to the email
   $this->email->subject('A Quote Has Been Requested');
   $this->email->message($message);
  
   $this->email->send();
  
  
   function thanks() {
    $data = array(
     'title' => 'Thank You!',
     'locations' => $this->locations,
     'readMore' => $this->readMore
    );
    $this->load->view('thanks_view', $data);
   }
  
   redirect('rfq/thanks');
  }
}

Code:
<?php
// Display Request for Quotation form
echo form_open_multipart('requestForm/contact2');

echo "<div>" . form_label('Name', 'name') . form_input('name', set_value('name')) . "</div>\n";
echo "<div>" . form_label('Company', 'company') . form_input('company', set_value('company')) . "</div>\n";
echo "<div>" . form_label('Street Address', 'street_address') . form_input('street_address', set_value('street_address')) . "</div>\n";
echo "<div>" . form_label('City', 'city') . form_input('city', set_value('city')) . "</div>\n";
echo "<div>" . form_label('State', 'state') . form_input('state', set_value('state')) . "</div>\n";
echo "<div>" . form_label('Zip', 'zip') . form_input('zip', set_value('zip')) . "</div>\n";

echo "<div>" . form_label('Phone', 'phone') . form_input('phone', set_value('phone')) . "</div>\n";
echo "<div>" . form_label('Email', 'email') . form_input('email', set_value('email')) . "</div>\n";$country = array(
'' => 'Click to Select',
//way too long to include
);
echo "<div>" . form_label('Country', 'country') . form_dropdown('country', $country) . "</div>\n";

$manufacturer = array(
  '' => 'Click to Select',
  //too long to include
);

echo "<div>" . form_label('Manufacturer', 'manufacturer') . form_dropdown('manufacturer', $manufacturer) . "</div>\n";
echo "<div>" . form_label('Part Number', 'part') . form_input('part', set_value('part')) . "</div>\n";
echo "<div>" . form_label('Quantity', 'quantity') . form_input('quantity', set_value('quantity')) . "</div>\n";

echo "<div>" . form_label('Date wanted by', 'datepicker') . form_input('datepicker', set_value('datepicker')) . "</div>\n";
$reference = array(
'' => 'Click to Select',
//too long to include
);
echo "<div>" . form_label('Sending a Spec Sheet?<br />(.pdf, .docx, .doc)', 'userfile') . form_upload('userfile', set_value('userfile')) . "</div>\n";
//cant add anymore
#2

[eluser]jairoh_[/eluser]
in your
Code:
$this->email->attach($datas['upload_data']['file_path'].$datas['upload_data']['file_name']);
try using only
Code:
$this->email->attach( $datas[ 'upload_data' ] [ 'full_path' ] );
#3

[eluser]cucaw[/eluser]
No. That didn't do anything. Thanks for taking the time to try to help though!
#4

[eluser]cucaw[/eluser]
So I figured out my problem. It was getting mad because it didn't have an error handler! To you it was something silly!
So for those of you who may have been having the same problem, this is what i was missing!
Code:
if ( ! $this->upload->do_upload())
         {
             $error = array('error' => $this->upload->display_errors());
            
             $this->load->view('name_of_file_with_upload_form', $error);
         }
#5

[eluser]TheFuzzy0ne[/eluser]
Have you tried sending the email to another account hosted by a different provider? Attaching a file should be as straightforward as what jairoh_ mentioned. I can't help thinking that somewhere along the line, a spam/virus filter may be emptying your attachment.

Have you tried any other file types, such as plain text?

Have you tried to use $this->email->print_debugger() to see what's happening?
#6

[eluser]TheFuzzy0ne[/eluser]
Also, do you realise you have a method within a method? Your thanks() method is defined within your contact2() method
#7

[eluser]cucaw[/eluser]
HA! Thanks! Silly me.




Theme © iAndrew 2016 - Forum software by © MyBB