简体   繁体   English

Codeigniter发送电子邮件引发错误

[英]Codeigniter Sending Email throwing error

I am spending hours trying to send email in CI from server. 我花了数小时试图从服务器以CI发送电子邮件。 In localhost, it worked fine. 在本地主机中,它工作正常。

In config/email.php I have added the following: config / email.php中,我添加了以下内容:

$config['mailtype'] = 'html';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';    
$config['smtp_port'] = 465;
$config['smtp_user'] = 'username@gmail.com';
$config['smtp_pass'] = '*******';
$config['charset'] = 'iso-8859-1';
$config['newline'] = "\r\n";

and in auth.php (I am using tank auth) in function for sending email, I have added this, 并在auth.php (我正在使用tank auth)中发送电子邮件的功能中,我添加了此功能,

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

I am getting errors as: 我收到以下错误消息:

A PHP Error was encountered

Severity: Warning

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

Filename: libraries/Email.php

Line Number: 1689

A PHP Error was encountered

Severity: Warning

Message: fwrite() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1846

A PHP Error was encountered

Severity: Warning

Message: fgets() expects parameter 1 to be resource, boolean given

Filename: libraries/Email.php

Line Number: 1869
.....................................................

I have enabled ssl in server. 我已在服务器中启用ssl。 I found lot of posts related to the same and followed them. 我发现了很多与此相关的帖子,并关注了它们。 But yet it is not sending email. 但是它没有发送电子邮件。

Can anyone help me to fix this? 谁能帮我解决这个问题? Thanks in advance. 提前致谢。

I think you forgot to load config.. 我认为您忘记了加载配置。

change 更改

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

To

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

However, have a look in this blog post for more information. 但是,请查看此博客文章以获取更多信息。 http://www.blog.orionwebtech.net/codeigniter-sending-email-via-smtp-gmail/ http://www.blog.orionwebtech.net/codeigniter-sending-email-via-smtp-gmail/

You can also check SSL is enabled - 您还可以检查SSL是否已启用-

You can enable SSL in your PHP config. 您可以在PHP配置中启用SSL。 Look up php.ini and find a line with the following: 查找php.ini并找到包含以下内容的行:

;extension=php_openssl.dll

Uncomment it. 取消注释。

extension=php_openssl.dll

Hope work. 希望工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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