如何使用 CodeIgniter 设置电子邮件配置


How to set up an email configuration using CodeIgniter?

我只是需要您帮助使用Codeigniter创建电子邮件发件人。我有这样的代码。在我的控制器中:

<?php
    class Email_Controller extends CI_Controller{
        public function __construct(){
            parent::__construct();
        }
        public function index(){
            $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'ssl://smtp.googlemail.com',
                'smtp_port' => 465,
                'smtp_user' => 'xxxxx@gmail.com', // change it to yours
                'smtp_pass' => 'xxxxx', // 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('xxxxx@gmail.com'); // change it to yours
            $this->email->to('xxxxx@gmail.com');// change it to yours
            $this->email->subject('Resume from JobsBuddy for your Job posting');
            $this->email->message($message);
            if($this->email->send()){
                echo 'Email sent.';
            }
            else{
                show_error($this->email->print_debugger());
            }
            $this->load->view("index");
        }
    }


?> 

如何配置电子邮件?

我收到此错误

A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553
An Error Was Encountered
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
From: 
Return-Path: 
Reply-To: "xxxxx@gmail.com" 
X-Sender: xxxxx@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <52805e90ecbed@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Resume_from_JobsBuddy_for_your_Job_posting?=

您需要在运行它的服务器上配置 smtp,如果它的垫子,灯,或者其他什么,一旦你这样做了,PHP函数电子邮件可能会成功发送电子邮件