【问题标题】:How to send email on localhost xampp in codeigniter?如何在codeigniter中的localhost xampp上发送电子邮件?
【发布时间】:2018-08-02 00:31:48
【问题描述】:

我尝试使用 codeigniter 在 localhost xampp 上发送电子邮件。 我按照指南修改了 xampp 中的 php.ini 和 sendemail.ini 文件。 我的codeigniter代码如下。

public function send_mail() {

        $config['useragent'] = 'CodeIgniter';
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_port'] = '587';
        $config['smtp_user'] = '****@gmail.com';
        $config['smtp_pass'] = '****';
        $config['smtp_timeout'] = 5;
        $config['wordwrap'] = TRUE;
        $config['wrapchars'] = 76;
        $config['mailtype'] = 'html';
        $config['charset'] = 'utf-8';
        $config['validate'] = FALSE;
        $config['priority'] = 3;
        $config['crlf'] = "\r\n";
        $config['newline'] = "\r\n";
        $config['bcc_batch_mode'] = FALSE;
        $config['bcc_batch_size'] = 200;
        $this->load->library('email', $config);

        $from_email = "csharpdev0423@gmail.com";
        $to_email = $this->input->post('email');
        //Load email library
        $this->load->library('email');
        $this->email->initialize($config);
        //$this->load->library('email', $config);
        $this->email->from($from_email, 'Identification');
        $this->email->to($to_email);
        $this->email->subject('Send Email Codeigniter');
        $this->email->message('The email send using codeigniter library');
        //Send mail
        if($this->email->send())
            $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
        else
            $this->session->set_flashdata("email_sent","You have encountered an error");
        $this->load->view('contact_email_form');
    }
    
    
但它有上述错误。

遇到 PHP 错误 严重性:警告

消息:fsockopen():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议

文件名:libraries/Email.php

行号:2055

【问题讨论】:

标签: php codeigniter


【解决方案1】:

您可以更改以下电子邮件配置数组。

<?php 
// change hostname
$config['smtp_host'] = 'smtp.gmail.com';

// change stmp port number
$config['smtp_port'] = '465';

// add smtp_crypto
$config['smtp_crypto'] = 'ssl';


// Change charset
$config['charset'] = 'iso-8859-1';

?>

希望它会有所帮助。

【讨论】:

  • 正确的 smtp_crypto 必须在 localhost 上,并且与 charset 具有 iso-8859-1 相同,因为 utf-8 在 localhost 上不支持 codeigniter 电子邮件,但如果您使用 phpmailer,则 charset utf-8 有效
猜你喜欢
  • 2018-03-08
  • 2012-05-07
  • 2014-07-22
  • 2018-10-16
  • 2016-05-13
  • 1970-01-01
  • 2019-03-06
  • 2016-07-29
  • 2012-01-27
相关资源
最近更新 更多