2

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?

Arcanyx
  • 852
  • 10
  • 25
GMehta
  • 39
  • 1
  • 5
  • What type of local host you using to test on? xammp wamp etc –  Jun 25 '15 at 06:32
  • Another thing is make some times codeigniter will not send unless send email settings are configured in xampp settings https://www.youtube.com/watch?v=TO7MfDcM-Ho –  Jun 25 '15 at 07:15

2 Answers2

1

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();
Saty
  • 22,443
  • 7
  • 33
  • 51
  • Thankyou. It took me out of the problem mentioned above but now it shows a lot of errors "fsockopen(): Unable to connect" Unable to send data . @Saty – GMehta Jun 25 '15 at 06:44
  • Sounds good you out of your problem!!. Now what error you got please paste your error – Saty Jun 25 '15 at 06:46
  • fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol fsockopen(): Failed to enable crypto fsockopen(): unable to connect to ssl://smtp.gmail.com:587 (Unknown error) fwrite() expects parameter 1 to be resource, boolean given Such errors @Saty – GMehta Jun 25 '15 at 06:48
  • little change in code `$this->load->library('email');` remove `$config` from this line – Saty Jun 25 '15 at 06:48
  • Change `'smtp_port' => 465`, to `'smtp_port' => 587`, and check – Saty Jun 25 '15 at 06:56
  • Done! Thankyou so much! – GMehta Jun 25 '15 at 07:04
  • Greetings! It throws an error when I try to initialize it this way. `fsockopen(): unable to connect to smtp.gmail.com:587 (Connection refused)` – Toma Tomov Nov 11 '19 at 22:01
0

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

Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85