无法使用CodeIgniter发送电子邮件 [英] Unable to send email with CodeIgniter

查看:272
本文介绍了无法使用CodeIgniter发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CI和PHP的新手。目前我使用xammp来运行PHP,Apache和MySql。现在我试图发送一封电子邮件与CI。但我经常遇到以下错误。

I am a novice to CI and PHP. Currently I'm using xammp to run PHP, Apache and MySql. Now I am trying to send an email with CI. But I constantly got an error as below.


遇到PHP错误

A PHP Error was encountered

严重性:警告

消息:fsockopen():无法连接到
ssl://smtp.googlemail.com:465
连接方在一段时间后没有正确响应,或
建立的连接失败,因为连接的主机未能响应
。)

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. )

档案名称:libraries / Email.php

Filename: libraries/Email.php

行号:1689

我有google大约三个小时,仍然没有找到解决方案。我已经在Apache中启用了' openssl '。

I have google about three hours and still not found the solution. I have already enabled 'openssl' in Apache. I would like to describe coding for my Email Controller Class.

//电子邮件控制器的索引函数的代码

//Code of Email Controller 'Index' function

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

    $config['charset'] = 'utf-8';
    $config['wordwrap'] = TRUE;
    $config['mailtype'] = 'html';
    $config['protocol'] = 'smtp';
    $config['smtp_port'] = 465;
    $config['smtp_host'] = 'ssl://smtp.googlemail.com';
    $config['smtp_user'] = "something@gmail.com";
    $config['smtp_pass'] = "xxx";

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

    $this->email->from('something@gmail.com', 'NayLinAung');
    $this->email->to('something@gmail.com');
    $this->email->subject('This is an email test');
    $this->email->message("It is working, Great! You will be successful.");

    if ($this->email->send())
    {
        echo "Email was successfully sent.";
    }
    else {  
        show_error($this->email->print_debugger());
    }



当我将smtp更改为mail时,不会发生错误,电子邮件实际上没有发送。此外,我关闭我的Windows防火墙。

When I change 'smtp' to 'mail', errors are not occurred but the email was not actually sent. In addition, I shutdown my Windows firewall.

请为此错误提出任何解决方案。

Please, suggest any solutions for this error.

推荐答案

我之前发现的是:

要在CodeIgniter中使用Google SMTP,您需要对您的Gmail帐户设置进行2(两个)更改:现在更容易攻击者入侵您的帐户 - Google)

To use Google SMTP in CodeIgniter you need to make 2 (two) changes into your Gmail account setting: (N.B. Please be aware that it is now easier for an attacker to break into your account -says Google)




  1. 允许安全性较低的应用:启用(或启用)

  1. Set off 2-step Verification.
  2. Allow less secure apps: ON (or Enable)


现在使用'smtp_host' ssl: //smtp.gmail.com 而不是 smtp.googlemail.com

问题也在此链接中讨论过。

希望有帮助。

这篇关于无法使用CodeIgniter发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆