编辑: 我正在尝试使用 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/