2

bellow code was working for other project of my but When I upload this to server then its not working can any one please help me out to resolved this issue.

I had created one helper file for send email

    $ci =& get_instance();
    $config = Array(
          'mailtype'  => 'html',
          'charset'   => 'iso-8859-1',
          'validate'  => TRUE ,
          'newline'   => "\r\n",
          'wordwrap'  => TRUE
    ); 

    $ci->load->library('email');
    $ci->email->initialize($config);

    $ci->email->from($fromemail, $fromname);
    $ci->email->reply_to(APPLICATION_EMAIL, SITENAME);
    $ci->email->to($toemail);

    $template_msg=str_replace($replace_array,$new_array,$tempmsg);

    $ci->email->subject(sprintf($subject, $data['site_name']));
    $ci->email->message($template_msg);
    $ci->email->send();  
Mukesh S
  • 367
  • 5
  • 19
  • What is the error message? From where do you get the vars $fromemail, $fromname, $tomail, $subject, $data['site_name'], $template_msg? – Lirux Aug 07 '15 at 07:26
  • I have created common function so this value came from function call. – Mukesh S Aug 07 '15 at 09:03

1 Answers1

1

First of all create a custom config file

email.php inside application/config

In my case i am sending email via webmail id,so here is my email.php

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'SMTP_HOST_NAME',
    'smtp_port' => 25,
    'smtp_user' => 'SMTP_USER_NAME', // change it to yours
    'smtp_pass' => 'SMTP_PASSWORD', // change it to yours
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);

Then make sure this config is autoloaded.Open your Autoload.php inside application/config and write

$autoload['config'] = array('email');

Now whenever you create a controller that has many methods using email library.use parent contruct

function __construct()
{
  parent::__construct();          
  $this->load->library('email', $config);

}

And then you can mails easily just be

$this->email->from('info@example.net', 'Account');
 $this->email->to('johndoe@example.com');
 $this->email->cc('johndoe@example.com');
 $this->email->bcc('johndoe@example.com');
 $this->email->subject('Account Confirmation');
 $message = "any message body you want to send";
 $this->email->message($message);
 $this->email->send();

This is the best when sending mails via CI email library.You can get more info. about CI email here. Thanks

Bugfixer
  • 2,547
  • 2
  • 26
  • 42