Php – Mail is not sending in php

codeigniteremailPHP

I have followed one tutorial to send mail from php.

 public function send_credentials($beneficiary_user){

  $this->load->library(‘email’);
  $email_config = Array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => '465',
        'smtp_user' => 'app123testing@gmail.com',
        'smtp_pass' => 'apptesting',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
    );
    $this->email->from('app123testing@gmail.com', 'invoice');
    $this->email->to('anilapu@navaratan.com');
    $this->email->subject('Invoice');
    $this->email->message('Test');

    $this->email->send();

}

What are the other settings i have to do to make it working
*After running echo $this->email->print_debugger();. I got*

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
     Date: Sun, 9 Feb 2014 14:58:44 +0530
     From: "invoice" 
     Return-Path: 
     Reply-To: "app123testing@gmail.com" 
     X-Sender: app123testing@gmail.com
     X-Mailer: CodeIgniter
     X-Priority: 3 (Normal)
     Message-ID: <52f74a4c41e32@gmail.com>
     Mime-Version: 1.0
     Content-Type: multipart/alternative; boundary="B_ALT_52f74a4c41e88"
      =?utf-8?Q?Invoice?=
      This is a multi-part message in MIME format.
      Your email application may not support this format.
     --B_ALT_52f74a4c41e88
     Content-Type: text/plain; charset=utf-8
     Content-Transfer-Encoding: 8bit
     Test
     --B_ALT_52f74a4c41e88
     Content-Type: text/html; charset=utf-8
     Content-Transfer-Encoding: quoted-printable
    Test
    --B_ALT_52f74a4c41e88--

Best Answer

Since we found the answer to your issue in the comments, it seemed prudent to write up an answer.

The problem was that your weren't doing anything with your email configuration array ($email_config). While you may or may not have had the right settings defined there, they meant nothing as they were not used properly.

Thus, at the very least, you must change your code to reflect the following changes:

$email_config = Array(
    'protocol'  => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => '465',
    'smtp_user' => 'app123testing@gmail.com',
    'smtp_pass' => 'apptesting',
    'mailtype'  => 'html',
    'starttls'  => true,
    'newline'   => "\r\n"
);

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

Please note that this will merely fix the issue with your approach, I cannot verify the credibility of your settings/access credentials.

EDIT:

As per jtheman's suggestion I decided to dig a bit deeper. You may want to look at this https://stackoverflow.com/a/17274496/2788532.

EDIT #2:

You can access useful error messages from CI's email class by using the following code (after you attempt to send an email, of course):

<?php echo $this->email->print_debugger(); ?>