Codeigniter email library sends weird format

Viewed 33

Hello and thank you for your help, I built a contact form in Codeigniter 3 which works, but when i use the email library to send my form I receive a weirdly formated email even though i specify the mailtype as html. This is my code:

View:

<form action="" method="post" class="contact-form">
                <input required="required" value="<?php echo !empty($postData['name']) ? $postData['name'] : ''; ?>"
                       type="text" name="name" class="contact-form-input first-input" placeholder="Nume">
                <input required value="<?php echo !empty($postData['email']) ? $postData['email'] : ''; ?>" type="email"
                       pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" name="email" class="contact-form-input"
                       placeholder="Email">
                <input required value="<?php echo !empty($postData['phone']) ? $postData['phone'] : ''; ?>" type="tel"
                       pattern="[+]?[0-9]{10,14}" name="phone" class="contact-form-input" placeholder="Telefon">
                <textarea name="message" class="contact-form-text"
                          placeholder="Mesaj"><?php echo !empty($postData['message']) ? $postData['message'] : ''; ?></textarea>
                <button id="Trimite" type="submit" value="submit" name="contactSubmit" class="contact-submit">Trimite</button>
</form>

Controller:

public function sendEmail($mailData)
    {

        $to = 'contact@asd.com';
        $from = $mailData['email'];
        $fromName = 'asd.asd';
        $mailSubject = 'Cerere de oferta trimisa de ' . $mailData['name'];

        $mailContent = '
            <h2>CERERE OFERTA</h2>
            <p><b>Name: </b>' . $mailData['name'] . '</p>
            <p><b>Email: </b>' . $mailData['email'] . '</p>
            <p><b>Phone: </b>' . $mailData['phone'] . '</p>
            <p><b>Message: </b>' . $mailData['message'] . '</p>
        ';
        $this->load->library('email');
        $config['mailtype'] = 'html';
        $this->email->initialize($config);
        $this->email->to($to);
        $this->email->from($from, $fromName);
        $this->email->subject($mailSubject);
        $this->email->message($mailContent);

        return $this->email->send() ? true : false;
    }

This is where i send it:

public function contact()
    {
        $this->load->helper('email');
        $data = $formData = array();
        if ($this->input->post('contactSubmit')) {
            $formData = $this->input->post();

            $this->form_validation->set_rules('name', 'Name', 'required');
//          $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
            $this->form_validation->set_rules('phone', 'Phone', 'required');
            $this->form_validation->set_rules('message', 'Message', 'required');

            if ($this->form_validation->run() == true) {
                $mailData = array(
                    'name' => $formData['name'],
                    'email' => $formData['email'],
                    'phone' => $formData['phone'],
                    'message' => $formData['message']
                );
                $send = $this->sendEmail($mailData);
                if ($send) {
                    header('location: https://asd.asd/success');
                } else {
                    $data['status'] = array(
                        'type' => 'error',
                        'msg' => 'Mesajul nu a fost trimis, va rugam sa incercati din nou'
                    );
                }
            }
        }
        // Pass POST data to view
        $data['postData'] = $formData;

        // Pass the data to view
        $this->load->view('contact', $data);
    }

And this is what i receive in my email client:

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_631dd81404150
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

CERERE OFERTA
 Name: test
 Email: test@test.com
 Phone: 1231231231
 Message: test message


--B_ALT_631dd81404150
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


 =3Ch2=3ECERERE OFERTA=3C/h2=3E
 =3Cp=3E=3Cb=3EName: =3C/b=3Etest=3C/p=3E
 =3Cp=3E=3Cb=3EEmail: =3C/b=3Etest=40test.com=3C/p=3E
 =3Cp=3E=3Cb=3EPhone: =3C/b=3E1231231231=3C/p=3E
 =3Cp=3E=3Cb=3EMessage: =3C/b=3Etest message=3C/p=3E

--B_ALT_631dd81404150--
0 Answers
Related