2

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--
user3289150
  • 39
  • 1
  • 1
  • 7
  • 1
    Can you describe the errors you are getting, both to console and in your error log – Rob Baillie Feb 09 '14 at 08:09
  • 3
    You're not doing anything with your `$email_config` array. You should pass it to the email lib when you are instantiating it. – Mark Feb 09 '14 at 08:21
  • call `$this->email->initialize($config);` to initialize the config variables you have set, or passing it in the constructor works as well `$this->load->library('email', $config);` – Andrew Brown Feb 09 '14 at 08:23
  • 1
    Good catch @RainFromHeaven. Completely missed that. – Gohn67 Feb 09 '14 at 08:28
  • But i am unable to understand.Where i have to use $this->load->library('email', $config);.Can you give proper directions. I am new to php. i don't how to make it working. @RainFromHeaven – user3289150 Feb 09 '14 at 08:33
  • @AndrewBrown It should be `$this->email->initialize($email_config);` and `$this->load->library('email', $email_config);` – jtheman Feb 09 '14 at 08:34
  • @RainFromHeaven You should write the reply so we can upvote! – jtheman Feb 09 '14 at 08:37
  • Thank you. I added $this->email->initialize($email_config); $this->load->library('email', $email_config);. Even though iam unable to send mail. – user3289150 Feb 09 '14 at 08:44
  • Not BOTH! See RainFromHeavens answer. – jtheman Feb 09 '14 at 08:44
  • I tried that one also.But mail is not sending – user3289150 Feb 09 '14 at 08:50
  • 2
    After you try to send the email, run this code: `echo $this->email->print_debugger()` and tell us what it returns. – Mark Feb 09 '14 at 09:00
  • After running sudo apt-get install postfix fixed my problem – user3289150 Feb 09 '14 at 09:58
  • Doesn't look like your config is set right. It should not be using the php mail function if using SMTP. See source here: https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Email.php#L1795 – Gohn67 Feb 09 '14 at 09:58

4 Answers4

8

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(); ?>
Community
  • 1
  • 1
Mark
  • 1,376
  • 9
  • 16
2

Just add this in start of the function where you are writing send email code

$config = Array(
          'protocol' => 'sendmail',
          'mailtype' => 'html', 
          'charset' => 'utf-8',
          'wordwrap' => TRUE

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

Email will forward but error same error will show

JoelC
  • 3,664
  • 9
  • 33
  • 38
Ali Umair
  • 690
  • 7
  • 10
1

you may try this

  1. Open system/libraries/email.php

  2. Edit

    var $newline = "\n"; var $crlf = "\n";

    to

    var $newline = "\r\n"; var $crlf = "\r\n";

0

make changes like this

'smtp_crypto'=>'ssl', //add this one
 'protocol' => 'smtp',
 'smtp_host' => 'smtp.gmail.com',
 'smtp_port' => 465,
Arsii Rasheed
  • 324
  • 1
  • 5
  • 18