简体   繁体   中英

Sending email from localhost using xampp to gmail with Codeigniter

Im trying to send an email from my localhost using xampp to Gmail with Codeigniter.

This is my code in the controller:

public function mail()
{
    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => 'kingkangddg@gmail.com',
        'smtp_pass' => '*****',
        'new_line' => "\r\n",
        );

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

    $this->email->from('kingkangddg@gmail.com', 'Glenn Samporna');
    $this->email->to('fajardokarlelbert@gmail.com');
    $this->email->subject('Test');
    $this->email->message('sample message');

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

}

It throws out errors like this:

hello: F

The following SMTP error was encountered: F
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

Date: Mon, 29 Jan 2018 09:35:37 +0100
From: "King Kang" <kingkangddg@gmail.com>
Return-Path: <kingkangddg@gmail.com>
To: fajardokarlelbert@gmail.com
Subject: =?UTF-8?Q?Test?=
Reply-To: <kingkangddg@gmail.com>
User-Agent: CodeIgniter
X-Sender: kingkangddg@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a6edcd99171d@gmail.com>
Mime-Version: 1.0


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

sample message

A PHP Error was encountered

Severity: Notice
Message: fwrite(): send of 6 bytes failed with errno=10053 An established connection was aborted by the software in your host machine.
Filename: libraries/Email.php
Line Number: 2242
Backtrace:

I hope you can help me out with this one.

Tested and worked fine on my local.

Changes

  1. Removed new_line
  2. Port changed.
  3. SMTP Encryption added. (4th argument)

Check My answer to another question how to configure mail setting in xampp
Check the php.ini for this path is there

sendmail_path   /usr/sbin/sendmail -t -i    /usr/sbin/sendmail -t -i 

Code

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.gmail.com',
    'smtp_port' => 587,
    'smtp_crypto' => 'tls',
    'smtp_user' => 'kingkangddg@gmail.com',
    'smtp_pass' => '*****',
);

Make sure: Two-way authentication turn offed and third-party access allowed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM