-4

我只需要您帮助我使用 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?=
4

1 回答 1

0

您需要在您正在运行的服务器上配置 smtp,如果它的 wamp、lamp 或其他任何东西,一旦您这样做,php 函数 email 可能会成功发送电子邮件

于 2013-11-11T07:05:04.790 回答