my problem is: Sending email with attachtment in Codeigniter 3.1.5 I want to send a form with name, email, phone and pdf file upload by user as attachment to email but I get problem. please help me
form:
<div>
<label for="name" class="label">Name:</label>
<input type="text" name="name">
</div>
<div>
<label for="email" class="label">Email:</label>
<input type="email" name="email">
</div>
<div>
<label for="email" class="label">Phone:</label>
<input type="text" name="phone">
</div>
<hr>
<div>
<label for="file">File: </label>
<input type="file" name="file">
</div>
<hr>
<button type="submit" name="submit" class="button is-danger" >Send Form</button>
</div>
<?php echo form_close(); ?>
And this is controller that the form return
Controller:
public function send(){
$config = [
'porotocol' => 'sendmail',
'smtp_host' => 'data',
'smtp_port' => 993,
'smtp_user' => 'email',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE,
];
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$data = [
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('phone'),
];
$this->email->from($data['email'], $data['name']);
$this->email->to('[email protected]');
$this->email->subject('form');
$file_name= $this->input->post('file');
$this->email->attach($file_name);
$message = $this->load->view('forms/formformat', $data, TRUE);
$this->email->message($message);
if($this->email->send()){
$this->session->set_flashdata("email_sent","ok");
redirect('forms/mailform');
} else {
$this->session->set_flashdata("email_nosent","error");
$data['content'] = 'forms/mailform';
$this->load->view('master', $data);
}
}
Also I have tried with upload library but the problem didn't solved. would you please help me how I can send the form with attachment to email. thank you