简体   繁体   中英

Codeigniter send email with image file

How i can send a php email with file & save in codeigniter? If i send the message from the site, i get the contact email, but without the file. My next idea is, that i need the "public function antrag" into the "public function mitgliedschaft", but it is not working.

Antrag = image file

What i try & result>>

Output Email:

Vorname: Testfirstname
Nachname: Testlastname
Email: email@email.com
Steam: Testurl
Antrag: 
Message: Testmessage

Controller

   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;
    }

view

<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>

我在视图的任何地方都看不到表单标签...如果要保存文件,必须为表单分配“ enctype =” multipart / form-data“”属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM