3

i want to send an email from my local host using code igniter. I'm using lamp here. My code shows below error

Exit status code: 127
Unable to open a socket to `Sendmail`. Please check settings.
Unable to send email using `PHP` `Sendmail`. Your server might not be configured to send mail using this method.

Date: Fri, 12 May 2017 08:01:46 +0200
From: "`jatin`" 
Return-Path: <xxx>
To: xxx
Subject: =?UTF-8?Q?Hi..=20?=
Reply-To: <xxx>
User-Agent: `CodeIgniter`
X-Sender: xxx
X-Mailer: `CodeIgniter`
X-Priority: 3 (Normal)
Message-ID: <xxx>
Mime-Version: 1.0

    Content-Type: text/plain; charset=UTF-8

Content-Transfer-Encoding: 8bit
user3079834
  • 2,009
  • 2
  • 31
  • 63
jatin
  • 49
  • 4

1 Answers1

3

Use PHP mailer for sending mail.

using this you can send mail easily without any warning and error

Download PHP mailer from here: PHPMailer

require_once(APPPATH.'third_party/PHPMailer/PHPMailerAutoload.php');
            $mail = new PHPMailer();
            $mail->IsSMTP(); 
            $mail->SMTPAuth   = true; 
            $mail->SMTPSecure = "ssl";  
            $mail->Host       = "smtp.gmail.com";     
            $mail->Port       = 465;                   
            $mail->Username   = "test@gmail.com";  // your email address
            $mail->Password   = "test";            // your gmail password
            $mail->SetFrom('test@gmail.com', 'Test');  //sender mail address
            $mail->isHTML(true);
            $mail->Subject    = "Subject";
            $mail->Body      = 'hello there';
            $destino = 'test@gmail.com'; // receiver email address
            $mail->AddAddress($destino, "Receiver");
            if(!$mail->Send()) {
                return false;
            } else {
                return true;
            }

You have to set access for less trusted apps in your Gmail account also:

  1. Login to your gmail account
  2. Click on MyAccount from Google Apps
  3. Click on 'Signing in to Google' from left panel
  4. And Turn on 'Allow less secure apps' from bottom of page

now try to send mail.it's works 100%.

Nidhi
  • 1,529
  • 18
  • 28
  • copied from [HERE](http://stackoverflow.com/questions/23988146/codeigniter-localhost-email-not-sending) You can mention actual link to answer rather than coping. – jagad89 May 12 '17 at 07:06
  • not copied from anywhere. I use this solution in my project. – Nidhi May 12 '17 at 07:09
  • A PHP Error was encountered Severity: Warning Message: fsockopen(): unable to connect to localhost:465 (Connection refused) Filename: libraries/Email.php Line Number: 2063 Backtrace: File: /opt/lampp/htdocs/jatin_EmailSend/application/controllers/Email_Control.php Line: 86 Function: send File: /opt/lampp/htdocs/jatin_EmailSend/index.php Line: 315 Function: require_once An Error Was Encountered The following SMTP error was encountered: 111 Connection refused Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. – jatin May 12 '17 at 07:15
  • make sure your `php_sockets` extension enabled. – jagad89 May 12 '17 at 07:16
  • it is enabled in php.ini file. ;extension=php_sockets.dll – jatin May 12 '17 at 07:28