Jake
Jake

Reputation: 1205

can't send html form email in Codeigniter

I am trying to send an email to customers with html form.

here is the controller file.

$email = '[email protected]';

$title = 'Introducing our new product!';

$msg = $this->load->view('admin/email_new_version', '', true);

$config['mailtype'] = 'html';
$this->load->library('email', $config);

$this->email->from('[email protected]', 'company');
$this->email->to($email); 

$this->email->subject($title);
$this->email->message($msg);    

$this->email->send();

It looks fine for me, but html doesn't work when I receive the mail.

Upvotes: 2

Views: 2749

Answers (4)

Ravi Mane
Ravi Mane

Reputation: 1536

  1. go system/libraries/email.php
  2. check $mailtype vairable value
  3. set $mailtype='html'

Upvotes: 1

Christian Giupponi
Christian Giupponi

Reputation: 7618

Try to use this configuration and try to initialize the email library in a separated command:

$this->load->library('email');
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);

This should work!

Upvotes: 2

Sed
Sed

Reputation: 6431

I think main area to focus on is whether or not you are using a local setup like wamp/lamp or any other local server installation where you are using a regular adsl connection with your ports not serving outside your lan.

You need to host your project in a hosting provider or open your ports to be able to serve to internet (the latter is not recommended without taking security precautions and also without having a mail server running this should not work) in order for email->send() function to work properly

Upvotes: 0

Robert
Robert

Reputation: 1907

The code looks fine. What do you mean when you say "html doesn't work when I receive the mail"? What kind of environment do you host it on?

Let's try simple debugging:

1) Check if the template is being loaded:

echo $this->load->view('admin/email_new_version', '', true);
die();

2) Validate your HTML.

3) Try setting different values in crlf, newline and charset preferences.

Upvotes: 1

Related Questions