Reputation: 377
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();
Upvotes: 2
Views: 735
Reputation: 2617
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('[email protected]', 'Account');
$this->email->to('[email protected]');
$this->email->cc('[email protected]');
$this->email->bcc('[email protected]');
$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
Upvotes: 1