How to send email with localhost using php CodeIgniter

I am working on a php codeigniter project and I want to send emails from my localhost.

Below are my controller functions.

        $config = Array(
              'protocol' => 'smtp',
              'smtp_host' => 'ssl://smtp.google.com',
              'smtp_port' => 465,
              'smtp_user' => 'sender@gmail.com',
              'smtp_pass' => 'password'
    );

    $this->load->library('email',$config);
    $this->email->set_newline("\r\n");

    $this->email->from("sender@gmail.com");
    $this->email->to("receiver@gmail.com");
    $this->email->subject("Email with Codeigniter");
    $this->email->message("This is email has been sent with Codeigniter");

    if($this->email->send())
    {
        echo "Your email was sent.!";
    } else {
        show_error($this->email->print_debugger());
    }

Please note that I allow the extension 'extension = php_openssl.dll' in php.ini. My php.ini file is located in C: / AppServ / php5. When I run the code, my page loads with errors.

These are the errors:

The following SMTP error occurred: 1923818231 Could not find the ssl transport socket - did you forget to enable it when you configured PHP? Failed to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:

Severity Level: Warning

: date(): . date.timezone date_default_timezone_set(). , , , , . "UTC" , , , date.timezone, .

: libraries/Email.php

: 705

0
2

PHPMailer. PHPMailer. :

public function send_mail()
    {
        require_once(APPPATH.'third_party/PHPMailer-master/PHPMailerAutoload.php');
        $mail = new PHPMailer();
        $mail->IsSMTP(); // we are going to use SMTP
        $mail->SMTPAuth   = true; // enabled SMTP authentication
        $mail->SMTPSecure = "ssl";  // prefix for secure protocol to connect to the server
        $mail->Host       = "smtp.gmail.com";      // setting GMail as our SMTP server
        $mail->Port       = 465;                   // SMTP port to connect to GMail
        $mail->Username   = "mail@gmail.com";  // user email address
        $mail->Password   = "password";            // password in GMail
        $mail->SetFrom('mail@gmail.com', 'Mail');  //Who is sending 
        $mail->isHTML(true);
        $mail->Subject    = "Mail Subject";
        $mail->Body      = '
            <html>
            <head>
                <title>Title</title>
            </head>
            <body>
            <h3>Heading</h3>
            <p>Message Body</p><br>
            <p>With Regards</p>
            <p>Your Name</p>
            </body>
            </html>
        ';
        $destino = receiver@gmail.com; // Who is addressed the email to
        $mail->AddAddress($destino, "Receiver");
        if(!$mail->Send()) {
            return false;
        } else {
            return true;
        }
    }

gmail.

+1

$config :

'smtp_host' => 'ssl://smtp.googlemail.com',
+2

Source: https://habr.com/ru/post/1648130/


All Articles