Welcome Guest, Not a member yet? Register   Sign In
Send File by Email through Form on Web Site?
#1

[eluser]invision[/eluser]
Hi,

I'm putting together a very basic job application script.

I want a user to be able to email a file (through a form on the web site) to me.

Where would I start with this?

I'm just looking for something basic that will work and then I can add to it.


Many thanks for any help.
#2

[eluser]eoinmcg[/eluser]
broadly speaking, there are two steps to what you want to achieve.

1. user uploads file via form on your website.
http://ellislab.com/codeigniter/user-gui...ading.html

2. you email the file from the server to whatever email addresses you want
http://ellislab.com/codeigniter/user-gui...email.html

the userguide has very clear, easy to understand examples that should get you started.

good luck!
#3

[eluser]invision[/eluser]
Hi Eoin. Many thanks. I'll take a look over those URLs and may come back.


Thanks
#4

[eluser]invision[/eluser]
Quick followup.

I'm proceeding fairly well with this.

However, have run into some errors Sad

I want to store the ID so I know which job is being applied for.

Code:
<?php
echo auto_typography($title);
echo auto_typography($body);
?>  
  <?php echo $this->validation->error_string; ?>
  <?php echo form_open_multipart('vacancies/apply/'); ?>
  &lt;!--<p><label for="email">E-mail: </label><br />&lt;?php echo form_input($email); ?&gt;</p>--&gt;
  &lt;?php
  echo "<p><label for='email'>Email</label><br />";
  $data = array('name'=>'email','id'=>'email','size'=>25, 'value' =>$post['email']);
  echo form_input($data) ."</p>"; ?&gt;

  &lt;?php echo form_hidden('slug',$post['slug']); ?&gt;
  &lt;?php echo form_submit('submit', 'Submit'); ?&gt;
  &lt;?php echo form_close(); ?&gt;

With this, I'm getting errors like:


A PHP Error was encountered
Severity: Notice

Message: Undefined variable: post

Filename: views/vacancies_apply.php

Line Number: 10



Any ideas what may be causing this?
#5

[eluser]Kamarg[/eluser]
$post isn't defined. You either want $_POST['email'] or $this->input->post('email').
#6

[eluser]invision[/eluser]
Aaah OK.

Do I have to define it in the View?

Here's my Model if it helps:

Code:
function apply($slug=0){
  
    $data['page_data'] = $this->MVacancies->getVacancyItem($slug);
    $data['page_data'] or redirect('vacancies/');
    
    $data['title'] = $data['page_data']['title'];
    $data['body'] = $data['page_data']['body'];
    
    #Validations
    $rules['email'] = "required|valid_email";
    $this->validation->set_rules($rules);
    
    #Input and textarea field attributes
    $data['email'] = array('name' => 'email', 'id' => 'email');
        
    if ($this->validation->run() == FALSE)
        {
            $data['main'] = 'vacancies_apply';
            $this->load->vars($data);    
            $this->load->view('template');
        }
        else
        {
            $email = $this->input->post('email');
                        
            $message = "$email has applied for this job.";
            $this->email->from($email, '[email protected]');
            $this->email->to('[email protected]');
            
            $this->email->subject('Application for Job #' . $id);
            $this->email->message($message);
            
            $this->email->send();
            
            $this->load->view('form_success');
        }
    
  }

Am I on the right track from looking at the above code?

Ultimately the email input field will change to a file input field.
#7

[eluser]invision[/eluser]
Could someone possibly lend a hand with this?

I'm happy to provide the code I have so far, or if there is an easier solution available?


Thanks for your help
#8

[eluser]eoinmcg[/eluser]
seems ok, what you're doing.

what part are you specifically having trouble with?

in terms of the upload and attachment;
- add an upload field to the form
Code:
<label>File</label>&lt;input type="file" name="file" /&gt;

- after validation is successful add in a check for an uploaded file and if present process the file
Code:
if($_FILES['file']['name'])
{
  $file_name = $this->_do_upload(); // _do_upload() should return the path and name of the uploaded file
  $this->email->attach($file_name);
}

- obviously, you'll have to write the _do_upload() method but there's enough in the user guide to make this a trivial task.
#9

[eluser]invision[/eluser]
Many thanks for the reply Eoin.

Here's my current VIEW for reference:

View
Code:
&lt;?php
echo auto_typography($title);
echo auto_typography($body);
?&gt;  
  &lt;?php echo $this->validation->error_string; ?&gt;
  &lt;?php echo form_open_multipart('vacancies/apply/'); ?&gt;
  <p><label>File</label>&lt;input type="file" name="file" /></p>

  &lt;?php echo form_hidden('slug',$post['slug']); ?&gt;
  &lt;?php echo form_submit('submit', 'Submit'); ?&gt;
  &lt;?php echo form_close(); ?&gt;
#10

[eluser]invision[/eluser]
Hi,

OK, I've managed to submit the form when attaching the file, but I now get these 2 errors when submitted:

Code:
A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for apply()

Filename: controllers/vacancies.php

Line Number: 38

and

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at ....system/libraries/Exceptions.php:166)

Filename: helpers/url_helper.php

Line Number: 541


The new Controller code is as follows:

Controller
Code:
function apply($slug){
  
    $data['page_data'] = $this->MVacancies->getVacancyItem($slug);
    $data['page_data'] or redirect('vacancies/');
    
    $data['title'] = $data['page_data']['title'];
    $data['body'] = $data['page_data']['body'];
    
      if(isset($_FILES['file']['name'])) {
      
              $email = 'Job Seeker';
              
        $file_name = $this->_do_upload(); // _do_upload() should return the path and name of the uploaded file
        $this->email->attach($file_name);
        
              $message = "$email has applied for this job.";
              $this->email->from($email, '[email protected]');
              $this->email->to('[email protected]');
              
              $this->email->subject('Application for Job #' . $id);
              $this->email->message($message);
              
              $this->email->send();
              
              $this->load->view('form_success');
              
          } else {
          
        $data['main'] = 'vacancies_apply';
        $this->load->vars($data);    
        $this->load->view('template');
        
      }
    
  }

I think I see the finishing lines.

Can you tell me if I've missed anything obvious?



Thanks again




Theme © iAndrew 2016 - Forum software by © MyBB