Php – Mail sent but not received, codeigniter

codeigniteremailPHPsmtp

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?

Best Answer

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();
Related Topic