2
votes

I have configured the following settings

 $config = Array(

        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'send-mail@gmail.com', // change it to yours
        'smtp_pass' => 'xyz', // change it to yours
        'smtp_timeout'=>20,
        'mailtype' => 'text',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
       );

$this->load->library('email',$config);
//$this->email->set_newline("\r\n");
$this->email->from('sender-mail@gmail.com', 'Garima');
$this->email->to('receiver-mail@gmail.com');

// mail message here

I get the following message:

Your message has been successfully sent using the following protocol: mail

From: "Garima" send-mail@gmail.com

Return-Path: send-mail@gmail.com

Reply-To: "send-mail@gmail.com"

X-Sender: send-mail@gmail.com

X-Mailer: CodeIgniter

X-Priority: 3 (Normal)

Message-ID: <@gmail.com>

Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit

Firstly,If i have defined the protocol as smtp, why does it show the protocol as mail.

Secondly, There is no "to" field in the message shown. Why is it so? what changes do i have to make?

2
What type of local host you using to test on? xammp wamp etcMr. ED
Another thing is make some times codeigniter will not send unless send email settings are configured in xampp settings youtube.com/watch?v=TO7MfDcM-HoMr. ED

2 Answers

1
votes

You forget to initialize the email config setting in your code

$this->email->initialize($config);

So your code would be

 $this->load->library('email');
        $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'ssl://smtp.gmail.com',
                'smtp_port' => 465,
                'smtp_user' => 'send-mail@gmail.com', // change it to yours
                'smtp_pass' => 'xyz', // change it to yours
                'smtp_timeout'=>20,
                'mailtype' => 'text',
                'charset' => 'iso-8859-1',
                'wordwrap' => TRUE
               );

         $this->email->initialize($config);// add this line

        //$this->email->set_newline("\r\n");
        $this->email->from('sender-mail@gmail.com', 'Garima');
        $this->email->to('receiver-mail@gmail.com');
        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');  
        $this->email->send();
        echo $this->email->print_debugger();
0
votes

Don't forget to load library first

$this->load->library('email');

then config these settings Can Refer here too

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',//your E-mail
    'smtp_pass' => 'xxx',//Your password
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);

$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com'); 
$this->email->cc('another@another-example.com'); 
$this->email->bcc('them@their-example.com'); 

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');  

$result = $this->email->send();

Send mail using localhost

  1. If you are using XAMPP do this settings Stack Answer for Send mail with XAMPP
  2. If you are sending mail with wamp Stack Answer for Send mail with WAMP

To read more about CI E-mail CI E-Mail Library