user3289150
user3289150

Reputation: 39

Mail is not sending in php

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' => '[email protected]',
        'smtp_pass' => 'apptesting',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
    );
    $this->email->from('[email protected]', 'invoice');
    $this->email->to('[email protected]');
    $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: "[email protected]" 
     X-Sender: [email protected]
     X-Mailer: CodeIgniter
     X-Priority: 3 (Normal)
     Message-ID: <[email protected]>
     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--

Upvotes: 2

Views: 21044

Answers (4)

Arsii Rasheed
Arsii Rasheed

Reputation: 351

make changes like this

'smtp_crypto'=>'ssl', //add this one
 'protocol' => 'smtp',
 'smtp_host' => 'smtp.gmail.com',
 'smtp_port' => 465,

Upvotes: 0

Snehasish Sarker
Snehasish Sarker

Reputation: 128

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";

Upvotes: 1

Ali Umair
Ali Umair

Reputation: 700

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

Upvotes: 3

Mark
Mark

Reputation: 1386

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' => '[email protected]',
    '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(); ?>

Upvotes: 8

Related Questions