0

I am trying to send an email from my localhost to user regarding for their forgotten password. (Test) This function is in my controller

// Send Request Email
public function send_email()
{
        $config = Array(
                                        'protocol' => 'smtp',
                                        'smtp_host' => 'ssl://smtp.googlemail.com',
                                        'smtp_port' => 465,
                                        'smtp_user' => '***@gmail.com', // change it to yours
                                        'smtp_pass' => '***', // change it to yours
                                        'mailtype' => 'html',
                                        'charset' => 'iso-8859-1',
                                        'wordwrap' => TRUE
                                    );

        $message = '';
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        $this->email->from('***@gmail.com', "Mama"); 
        $this->email->to('***@gmail.com');
        $this->email->subject('Mama Needs You');
        $this->email->message($message);

        if($this->email->send())
        {
                echo 'Email sent to Mama.';
        }
        else
        {
                show_error($this->email->print_debugger());
        }
}

Once the user enter his email and click the request button, the function above (send_email) will be requested by AJAX call. But the reply is this

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

Filename: libraries/Email.php

Line Number: 2055

Backtrace:

File: D:\xampp\htdocs\prototype\application\controllers\Manage.php Line: 191 Function: send

File: D:\xampp\htdocs\prototype\index.php Line: 315 Function: require_once

A PHP Error was encountered Severity: Warning

Message: fsockopen(): Failed to enable crypto

Filename: libraries/Email.php

Line Number: 2055

Backtrace:

File: D:\xampp\htdocs\prototype\application\controllers\Manage.php Line: 191 Function: send

File: D:\xampp\htdocs\prototype\index.php Line: 315 Function: require_once

A PHP Error was encountered Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Unknown error)

Filename: libraries/Email.php

Line Number: 2055

Backtrace:

File: D:\xampp\htdocs\prototype\application\controllers\Manage.php Line: 191 Function: send

File: D:\xampp\htdocs\prototype\index.php Line: 315 Function: require_once

1 Answers1

-1

**Try This **

    public function index()
    {
        $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'smtp3.netcore.co.in',
        'smtp_port' => 25,
        'smtp_user' => 'support@9abusiness.com',
        'smtp_pass' => 'Supp0rt',
        'mailtype'  => 'html', 
        'charset' => 'utf-8',
        'wordwrap' => TRUE
    );

        $this->load->library('email',$config);
        $this->email->from('support@9abusiness.com', 'Support');
        $this->email->to('abdularbaaz@gmail.com');
        $this->email->cc('');
        $this->email->bcc('');

        $this->email->subject('Test');
        $this->email->message('This is a test email');

    if ( ! $this->email->send())
{
    // Generate error
    echo "Email is not sent!!";
}

        echo $this->email->print_debugger();

    }

}
Pardeep
  • 2,153
  • 1
  • 17
  • 37
  • thank you for replying to my question sir @pardeep , i tried your code above and this is the reply of the AJAX call: Message: fsockopen(): unable to connect to smtp3.netcore.co.in:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) – Software Section ACDI Jan 31 '18 at 03:56
  • Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. – Software Section ACDI Jan 31 '18 at 03:59
  • Do you have an email.php file in your config folder? Maybe there's a problem with your configuration in there.Maybe you should try $config['mailtype'] = 'text'; The mailtype html already caused some problems for me. Or try deleting the whole config file to use default settings – Pardeep Jan 31 '18 at 04:17
  • i dont have email.php in my config folder.. i only have that line of code above in my controller – Software Section ACDI Jan 31 '18 at 05:16
  • i tried to delete the config code in my controller still the error is the same as i mentioned above :/ i feel hopeless – Software Section ACDI Jan 31 '18 at 05:18
  • https://stackoverflow.com/questions/38203839/fsockopen-unable-to-connect-to-ssl-smtp-gmail-com465 May be this one will Help You – Pardeep Jan 31 '18 at 05:22
  • Did You Use these codes on online server or offline server ? – Pardeep Jan 31 '18 at 06:11
  • im using it on my laptop sir with internet connection – Software Section ACDI Jan 31 '18 at 06:33
  • No you need to use online server thats the problem when u use mail system – Pardeep Jan 31 '18 at 06:47
  • i see.. can i use phpmailer on behalf of mail system incogniter? i want to test the sending email process – Software Section ACDI Jan 31 '18 at 06:57
  • You Can use php mailer I have the code of php mailer if you want. I can Send You but all mailing sytem works on online servers – Pardeep Jan 31 '18 at 07:00
  • Are those real login details? OP was trying to use SSL/465, and the error msg is related to that. Switching to unsecured port 25 is not a real solution. And posting your mail in plain text to a random mail server on the internet? Sorry, but I downvoted, I think this is very bad advice. – Don't Panic Jul 17 '20 at 08:04