我的问题是:在Codeigniter 3.1.5中发送带附件的电子邮件 我想发送一个名称,电子邮件,电话和pdf文件上传的表格作为电子邮件的附件,但我遇到了问题。请帮帮我
形式:
<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(); ?>
这是表单返回的控制器
控制器:
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('test@test.com');
$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);
}
}
我也试过上传库,但问题没有解决。 你能不能帮助我如何发送带有电子邮件附件的表格。 谢谢
答案 0 :(得分:0)
这个代码为我解决了:
$aConfig['upload_path'] = './uploads/';
$aConfig['allowed_types'] = 'pdf';
$aConfig['max_size'] = '3000';
$config['encrypt_name'] = true;
$this->load->library('upload', $aConfig);
foreach ($_FILES as $key => $file)
{
if ($file['error'] == 0)
{
$this->email->attach($file['tmp_name'], '', $file['name']);
}
}