php - 在 Codeigniter 电子邮件库中调用发送方法时出错

标签 php codeigniter email

编辑: 我正在尝试使用 codeigniter 的库发送电子邮件。每当我调用 $this->email->send() 函数时,它都会返回

Warning: include(C:\xampp\htdocs\psems\application\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\xampp\htdocs\psems\system\core\Exceptions.php on line 269

Warning: include(): Failed opening 'C:\xampp\htdocs\psems\application\views\errors\html\error_php.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\psems\system\core\Exceptions.php on line 269

这是我目前的代码

 $config = array();
    $config['useragent']           = "CodeIgniter";
    $config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
    $config['protocol']            = "smtp";
    $config['smtp_host']           = "localhost";
    $config['smtp_port']           = "25";
    $config['mailtype'] = 'html';
    $config['charset']  = 'utf-8';
    $config['newline']  = "\r\n";
    $config['wordwrap'] = TRUE;

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

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

    $this->email->from('example@gmail.com', 'harold decapia');
    $this->email->to('example@gmail.com');

    $this->email->subject('Тест Email');
    $this->email->message('Hello World');

    $this->email->send(); //I tried commenting this out and there was no error returned

我很困惑为什么它只是通过调用 send 方法就返回错误。我必须先配置一些东西吗?我想我在这里遗漏了一点点信息:(

还有,有什么方法可以让我知道它具体返回了什么错误吗?提前谢谢你

最佳答案

据我所知,错误的出现是因为您试图在没有实际 FTP 服务器的服务器上使用 SMTP 发送电子邮件(在本地服务器上经常发生)。

我要推荐一个像Mailgun这样的免费服务在开发时用作 SMTP 服务器。

此外,如果您要使用 SMTP 协议(protocol),则需要使用用户名和密码在 SMTP 服务器上进行身份验证(Mailgun 也会为您提供)。

这是 SMTP 服务器/身份验证的新配置示例,请记住您需要根据 Mailgun 网站将在您的帐户上提供给您的信息进行调整。

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.mailgun.org';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '30';
$config['smtp_user'] = 'postmaster@mydomain.com';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";

:)

关于php - 在 Codeigniter 电子邮件库中调用发送方法时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955991/

相关文章:

php - 使用 Nginx 在 OpenSuse 上启用 php5-curl

php - Mysql 仅返回具有 n 个属性匹配的项目

php - 发生数据库错误

email - symfony2 + fos 用户 bundle ,未收到注册确认邮件

python - 使用 python 转发 html 电子邮件

php - 尽管验证码有效,用户应该如何通过输入无效的电子邮件 ID 在网站上注册?

php - 在我的本地 Windows 机器上,我如何编写一个脚本来每天下载漫画并将其通过电子邮件发送给自己?

codeigniter - 在 CodeIgniter 中的 Controller URI 段之前传递变量

CodeIgniter - 在非对象上调用成员函数 model()

php - 我怎样才能使这个插入免受 MySQL 注入(inject)的影响?