0

I have a problem like this.I want to send a mail from my web application so I put this in my controller.

$from_email = "tharuwan40@gmail.com";
$to_email = "warimali94@gmail.com";

//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Info');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

This web application is still running on localhost.I tried so many examples in the net and which have been posted in stack overflow tooo.But there was nothing on my mail.Email was not send.How can I get fix this?

Tharindu Sandaruwan
  • 195
  • 1
  • 2
  • 12

1 Answers1

0

Create config array

 $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx@gmail.com',// your mail name
    'smtp_pass' => '*****',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
    'wordwrap' => TRUE
);

then

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

  $this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
  $this->email->to('target@gmail.com'); //receiver mail

  $this->email->subject('testing');
  $this->email->message($message);

  if($this->email->send()) //sending mail
  {
     echo 'Mail sent';
  }
  else
  { 
     print_r($this->email->print_debugger(), true);
  }

Configuration in sendmail.ini

path [xampp folder]\sendmail\sendmail.ini

Configurations

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com

open php.ini config file and search for[mail function]

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Restart Server

Main Source

Param Bhat
  • 470
  • 1
  • 6
  • 17
  • is smtp_pass my email password? – Tharindu Sandaruwan Feb 13 '18 at 04:14
  • Unable to send email using PHP mail(). Your server might not be configured to send mail using this method. Date: Tue, 13 Feb 2018 05:22:38 +0100 From: "Tharindu" Return-Path: Reply-To: User-Agent: CodeIgniter X-Sender: tharindusandaruwan40@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <5a82680ed8629@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit =?UTF-8?Q?testing?= test – Tharindu Sandaruwan Feb 13 '18 at 04:25
  • It gave me like this – Tharindu Sandaruwan Feb 13 '18 at 04:25
  • I have modified my code. Please try above changes in configuration. – Param Bhat Feb 13 '18 at 04:59