使用带有Codeigniter电子邮件库的gmail smtp发送电子邮件

class Email extends Controller {

    function Email()

{

parent::Controller();

$this->load->library('email');

}

function index()

{

$config['protocol'] = 'smtp';

$config['smtp_host'] = 'ssl://smtp.gmail.com';

$config['smtp_port'] = '465';

$config['smtp_timeout'] = '7';

$config['smtp_user'] = 'mygmail@gmail.com';

$config['smtp_pass'] = '*******';

$config['charset'] = 'utf-8';

$config['newline'] = "\r\n";

$config['mailtype'] = 'text'; // or html

$config['validation'] = TRUE; // bool whether to validate email or not

$this->email->initialize($config);

$this->email->from('mygmail@gmail.com', 'myname');

$this->email->to('target@gmail.com');

$this->email->subject('Email Test');

$this->email->message('Testing the email class.');

$this->email->send();

echo $this->email->print_debugger();

$this->load->view('email_view');

}

}

我收到此错误:

A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out)

Filename: libraries/Email.php

Line Number: 1641

使用 PORT 25/587

我收到此错误:

A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:func(119):reason(252)

Filename: libraries/Email.php

Line Number: 1641

我现在不想使用phpmailer。(实际上,我尝试使用phpmailer,但失败了)。

我该如何解决这个问题?

回答:

$config = Array(

‘protocol’ => ‘smtp’,

‘smtp_host’ => 'ssl://smtp.googlemail.com’,

‘smtp_port’ => 465,

‘smtp_user’ => ‘xxx’,

‘smtp_pass’ => ‘xxx’,

‘mailtype’ => ‘html’,

‘charset’ => ‘iso-8859-1’

);

$this->load->library(‘email’, $config);

$this->email->set_newline(“\r\n”);

// Set to, from, message, etc.

$result = $this->email->send();

以上是 使用带有Codeigniter电子邮件库的gmail smtp发送电子邮件 的全部内容, 来源链接: utcz.com/qa/410111.html

回到顶部