我如何发送带有文件和电子邮件的php电子邮件保存在codeigniter? 如果我从网站发送消息,我会收到联系电子邮件,但没有该文件。我的下一个想法是,我需要"公共功能antrag"进入"公共职能mitgliedschaft",但它无效。
Antrag =图片文件
我尝试和做什么导致>>
输出电子邮件:
Vorname: Testfirstname
Nachname: Testlastname
Email: email@email.com
Steam: Testurl
Antrag:
Message: Testmessage
控制器
public function mitgliedschaft() {
$this->load->library('form_validation');
$this->form_validation->set_rules('vorname', 'Vorname', 'trim|required');
$this->form_validation->set_rules('nachname', 'Nachname', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('steam', 'Steam', 'trim|required');
$this->form_validation->set_rules("antrag", 'Antrag', "trim|callback_antrag[$id]");
$this->form_validation->set_rules('message', 'Message', 'trim|required');
$data['success'] = false;
if ($this->form_validation->run() == TRUE) {
@mail(config('webmaster_email'), 'Message from eraseme', ""
. "Vorname: $_POST[vorname]\n"
. "Nachname: $_POST[nachname]\n"
. "Email: $_POST[email]\n"
. "Steam: $_POST[steam]\n"
. "Antrag: $_POST[antrag]\n"
. "Message: $_POST[message]\n"
. "");
$data['success'] = true;
}
$this->load->view(__FUNCTION__, $data);
}
public function antrag($var, $id) {
$config['upload_path'] = './cdn/antrag/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
if ($this->upload->do_upload('antrag')) {
$data = $this->upload->data();
if ($data['file_name'])
$this->{$this->model}->antrag = base_url() . '/cdn/antrag/' . $data['file_name'];
}
return true;
}
查看
<div class="controls">
<div class="row">
<?php if ($success) : ?>
<div class="col-md-12">
<div class="alert alert-success">
<i class="fa fa-check-circle" aria-hidden="true" style="margin-left: 7px;"></i>
Your Message Is Sent Successfully
</div>
</div>
<?php endif ?>
<?php if (validation_errors()) : ?>
<div class="col-md-12">
<div class="alert alert-danger">
<i class="fa fa-times-circle" aria-hidden="true" style="margin-left: 7px;"></i>
<?php echo validation_errors() ?>
</div>
</div>
<?php endif ?>
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Vorname *</label>
<input id="form_name" type="text" name="vorname" id="vorname" class="form-control" placeholder="Please enter your firstname *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Nachname *</label>
<input id="form_name" type="text" name="nachname" id="nachname" class="form-control" placeholder="Please enter your lastname *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_email">Email *</label>
<input id="form_email" type="email" name="email" id="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="form_phone">Steam URL</label>
<input id="form_phone" type="tel" name="steam" id="steam" class="form-control" placeholder="Please enter your Steam URL or ID">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input class="form-control" type="file" name="antrag" >
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="form_message">Message *</label>
<textarea id="form_message" name="message" id="message" class="form-control" placeholder="Message for me *" rows="4" required="required" data-error="Please,leave us a message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12">
<input type="submit" id="send" class="btn btn-success btn-send whibtn" style="margin:0;" value="Send message">
</div>
</div>
</div>
答案 0 :(得分:0)
我在视图中的任何位置都看不到您的表单标记...如果要保存文件,则必须为表单分配“enctype =”multipart / form-data“”属性