0

I want to send mail using codeigniter. I am using codeigniter as mailer. i have written a controller and upload it on net . when i call the controller. This shows errors.I am writing my controller like

<?php

class Testmail extends CI_Controller {

    public $data = array();

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url_helper');
        $this->load->helper(array('form', 'url'));
        $this->load->library('email');
        $this->load->helper('url'); 

    }

    public function mailsend()
    {
            $config['protocol'] = 'sendmail';
            $config['mailpath'] = '/usr/sbin/sendmail';
            $config['charset'] = 'iso-8859-1';
            $config['wordwrap'] = TRUE; 
            $this->email->initialize($config);

            $this->email->from('kunal.saxena.kunal@gmail.com', 'Your Name');
            $this->email->to('kunal.saxena.kunal@gmail.com'); 
            $this->email->subject('Email Test');
            $this->email->message('Testing the email class.');  

            $this->email->send();

            echo $this->email->print_debugger();


    }
}

But it is not working and i got the error like

Exit status code: 127
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Mon, 28 May 2012 10:51:18 +0000
From: "Your Name" 
Return-Path: 
To: kunal.saxena.kunal@gmail.com
Subject: =?iso-8859-1?Q?Email_Test?=
Reply-To: "kunal.saxena.kunal@gmail.com" 
X-Sender: kunal.saxena.kunal@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4fc358a653ad4@gmail.com>
Mime-Version: 1.0


Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Testing the email class.

How to remove this error..?

hakre
  • 193,403
  • 52
  • 435
  • 836
kunal saxena
  • 398
  • 1
  • 6
  • 13
  • You need to configure `sendmail` on your server. Check if you have sendmail installed at all and that `sendmail_path` is correctly set up in php.ini. –  May 28 '12 at 11:14
  • Looks everything fine ....Just make sure your server if configure properly..I have also used this script in codeigniter and that works well for me. – Pramod Kumar Sharma May 28 '12 at 11:29
  • It appears you are simply copying and pasting code found instead of reading the manual. Try removing the following lines `$config['protocol'] = 'sendmail'; $config['mailpath'] = '/usr/sbin/sendmail'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = TRUE; $this->email->initialize($config); ` – Gavin May 28 '12 at 14:08
  • Why do you expect your code to work? Please provide reference for your assumptions that it should work that way. – hakre May 29 '12 at 13:12
  • yap when i configure send mail on my server it code works fine.Thanks everyone – kunal saxena Jun 25 '12 at 07:12

2 Answers2

0

Make sure your server has sendmail and it is correctly set up, In case you don't have it and can't install it you can use googles SMTP server to send emails, this is what I do on localhost. You can find and example of how to do it here

PS. Controller looks fine

Community
  • 1
  • 1
greenLizard
  • 2,326
  • 5
  • 24
  • 30
  • Google can only be used if you have SSL installed on the server hosting the website. – Gavin May 28 '12 at 14:07
  • If you're having trouble using Gmail as a third party, there are other services that you can integrate. SendGrid, Amazon SES and PostageApp.com for example. At PostageApp we have a CI plugin to make this integration smoother - http://github.com/postageapp/postageapp-codeigniter Disclaimer: I work for PostageApp – tomwalsham May 28 '12 at 18:48
  • I was using amazon ec2 server. And this issue gets resolved when i configure smtp installation on ubuntu. After that things works fine. – kunal saxena Mar 23 '13 at 03:57
0

You need to have an MTA (mail transfer agent) installed on the computer to actually send the email, and PHP needs to be configured to use it to send email.

If you're using Linux or OS X as your development environment, I can highly recommend msmtp as an easy-to-configure solution for this. It's really easy to get it working with pretty much any email account, and it's also easy to get PHP to talk with it. I use exactly this setup on my Ubuntu development machine with a CodeIgniter project at work, and it works really well. There's a great tutorial that covers this on the Arch Linux wiki, although most of it should be relatively easy to adapt to other Linux distros or OS X.

Matthew Daly
  • 9,212
  • 2
  • 42
  • 83